Android的 - 移除];更多动作;从动作条按钮 [英] Android - Remove "More actions" button from the ActionBar
问题描述
我有,应该显示操作按钮自定义方式的动作条。为此,我创建了一个自定义视图和连接它的动作条。
I have an ActionBar that should display the action buttons in a custom way. For this I created a custom view and attached it to the ActionBar.
有一点要提的是,我使用的是 menu.xml文件资源库文件加载选项菜单,并在智能手机上显示出来,但不会在平板电脑上显示出来,而不是使用自定义视图。为此,我的市场在XML,因为每个菜单项:安卓showAsAction =从不
One thing to mention is that I am using a menu.xml resoure file to load the options menu and display them on a smartphone, but do not display them on tablet, instead use a custom view. For this I market every menu item in the xml as: android:showAsAction="never"
一切看起来正常,但一个小东西仍然保留在动作条的权利 - 更多按钮。
Everything looks fine, except one little thing that still remains on the right of the ActionBar - the "More" button.
我怎么能删除吗?
我尝试这样做:
ActionBar bar = activity.getActionBar();
bar.removeAllTabs();
但更多按钮仍然存在。
but the "more" button still remains there.
编辑:
这是我menu.xml文件文件:
This is my menu.xml file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_username"
android:icon="@drawable/menu_username"
android:orderInCategory="0"
android:showAsAction="never"
android:title="@string/menu_username">
<menu>
<item
android:id="@+id/menu_logout"
android:title="@string/menu_logout"/>
</menu>
</item>
<item
android:id="@+id/menu_settings"
android:icon="@drawable/menu_settings"
android:orderInCategory="1"
android:showAsAction="never"
android:title="@string/menu_settings"/>
<item
android:id="@+id/menu_search"
android:icon="@drawable/menu_search"
android:orderInCategory="1"
android:showAsAction="never"
android:title="@string/menu_search"/>
</menu>
请注意,我还是想夸大在智能手机这个菜单,但不希望使用它在平板电脑上。
推荐答案
设置 showAsAction从来没有=
将迫使一个菜单项进入溢流。为什么不检查onCreateOptionsMenu(...),该装置是一个平板电脑,如果它是不膨胀的菜单吗?事情是这样的:
Setting showAsAction="never"
will force an menu item into the overflow. Why not check in onCreateOptionsMenu(...) that the device is a tablet, and if it is just not inflate the menu? Something like this:
public boolean onCreateOptionsMenu(Menu menu) {
if (getResources().getConfiguration().smallestScreenWidthDp >= 600) {
//It's a tablet, don't inflate, only create the manual view
manualMenuCreation();
} else {
getMenuInflater().inflate(R.menu.menu, menu);
}
return true;
}
不要忘记 smallestScreenWidthDp
仅在3.2或以上可用,所以你必须要考虑到这一点。
Don't forget smallestScreenWidthDp
is only available in 3.2 or above, so you'll have to take that into consideration.
这篇关于Android的 - 移除];更多动作;从动作条按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!