android - 如何确定选项菜单对象在 Android ActionBar 中的相对位置?

标签 android android-actionbar

在 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:showAsActionifRoom

您可以将其作为用户的配置选项,以便用户选择要使用的样式。

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/

相关文章:

android - 为多个对象使用通用类(actionBar 选项卡)

android - ActionBar 中可绘制的后退箭头的 ID 是什么?

android - Viewpager 中 fragment 的 OptionsMenu 显示彼此的按钮

android - 展开搜索 View 以使用整个操作栏(隐藏其他内容)

android - Oppo - 安装*.apk 失败 : Failure [-99]

Android:在TextView中静态下划线动态文本

android - Google Play 更新了描述和屏幕截图,但没有更新应用程序 apk

java - 如何将 EasyPost 库添加到 Android Studio 项目

android - ActionBarSherlock 是否允许启用/禁用 ActionBar.Tab?

android - Dagger 2 没有注入(inject) sharedPreference