在 Honeycomb ActionBar 中,我试图确定显示为我的 ActionBar 的“showAsAction”选项的图标的位置。我的几个图标设置为仅在有空间时显示。我想在应用程序首次运行时在每个图标下包含有用的注释。为了正确定位评论,我需要了解这些图标的位置。
我从 Activity 中调用了 getActionBar(),但图标没有出现在 ActonBar 的 View 中。我知道我可以通过 OptionsMenu 的 onPrepare 和 onCreate 获取菜单项的句柄,但它们不包含任何定位信息,因为 ActionBar 尚未呈现。有任何想法吗?我还探索了 onMenuVisibilityListener,但此时的 ActionBar 仍然不包含任何可用于计算选项菜单图标相对位置的信息。
如果有一种方法也可以确定哪些操作栏项目实际出现,我也可以计算出放置东西的位置。
最佳答案
I want to include helpful comments under each icon when the application is first run.
然后在第一次运行时加载不同的菜单 XML 资源,其中包含 withText
以及 android:showAsAction
的 ifRoom
。
您可以将其作为用户的配置选项,以便用户选择要使用的样式。
If there is a way to also just determine which actionbar items are actually appearing, I can calculate where to place things too.
除了你实际上不能在那里放置任何东西。工具栏按钮占据整个操作栏高度。
关于android - 如何确定选项菜单对象在 Android ActionBar 中的相对位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7780013/