我正在使用ActionBarSherlock,我正在尝试向ActionBar添加一个选项菜单。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_prev"
android:title="@string/menu_previous"
android:icon="@drawable/left_navigation"
android:showAsAction="always|withText" />
<item android:id="@+id/menu_next"
android:title="@string/menu_next"
android:icon="@drawable/right_navigation"
android:showAsAction="always|withText" />
</menu>
图标是可绘制 mdpi 目录中的 32x32 像素。 当操作栏被分割(纵向)时,图标会显示,但没有文本显示(虽然空间很大)。 长按图标可烘烤标题。 当操作栏未拆分(横向)时,图标和文本都会按预期显示。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
Menu、MenuInflater 和 getSupportMenuInflater() 都使用 ActionBarSherlock 实现。
清单中的"应用程序"声明:
android:uiOptions="splitActionBarWhenNarrow"
如何使其在纵向时显示每个项目的标题?
编辑:可能相关的是我正在运行Android 4.0.4。
如果您使用的是Android>= 3.0 ABS使用操作栏的系统实现,因此您看到的行为是正确的。请参阅@CommonsWare对为什么行为如此的问题的评论。