showAsAction=“ifRoom"即使有足够的空间也不显示该项目 [英] showAsAction="ifRoom" doesn't show the item even when there is plenty of room
问题描述
我正在尝试让 ActionBar 在我的应用程序上正常工作(并且我正在使用 ActionBarSherlock 在 Android 2.x 和 4.x 之间获得统一的 UI).
I am trying to get the ActionBar working properly on my app (and I'm using ActionBarSherlock to get a unified UI between Android 2.x and 4.x).
我觉得 android:showAsAction="ifRoom"
只是一个大大的谎言.每当我将操作设置为 ifRoom
时,它总是会显示在溢出菜单中,即使有足够的空间.这是来自同一个模拟器的两个屏幕截图.第一个显示所有选项设置为 always
的 ActionBar,第二个显示最后两个选项设置为 ifRoom
的 ActionBar.正如您所看到的,当它们都显示在 always
屏幕截图中时,有很多空间,那么为什么它们没有全部显示在第二个中,因为它们确实有空间?
I feel like android:showAsAction="ifRoom"
is just a big, fat lie. Whenever I set an action to ifRoom
it ALWAYS shows up in the overflow menu even if there is PLENTY of room. Here are two screenshots from the same emulator. The first shows the ActionBar with all options set to always
and the second shows the ActionBar with the last two options set to ifRoom
. As you can see, there was PLENTY of room when they were all shown in the always
screenshot, so why aren't they all showing in the second because they DO have room?
这是我的 menu.xml:
Here is my menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/add"
android:icon="@drawable/ic_menu_btn_add"
android:showAsAction="always"
android:title="Add"/>
<item
android:id="@+id/calculateNPV"
android:icon="@drawable/menu_icon_npv"
android:showAsAction="always"
android:title="NPV"/>
<item
android:id="@+id/calculateIRR"
android:icon="@drawable/menu_icon_irr"
android:showAsAction="always"
android:title="IRR/YR"/>
<item
android:id="@+id/send"
android:icon="@android:drawable/ic_menu_share"
android:showAsAction="always"
android:title="@string/share_pdf"/>
<item
android:id="@+id/graph"
android:icon="@drawable/ic_menu_gallery"
android:showAsAction="ifRoom"
android:title="@string/view_cashflow_diagram"/>
<item
android:id="@+id/deleteReorder"
android:icon="@drawable/ic_menu_clear_playlist"
android:showAsAction="ifRoom"
android:title="@string/delete_reorder_cashflows"/>
</menu>
推荐答案
我希望我来参加聚会不会太晚.
I hope I am not too late in coming to the party.
这真的不是一个大谎言,而是一个小疏忽.
It is really not a big fat lie but a small oversight.
showAsAction
属性必须使用不同的命名空间 "http://schemas.android.com/apk/res-auto"
The showAsAction
attribute must be defined using a different namespace "http://schemas.android.com/apk/res-auto"
因此,您应该在顶部菜单标签中定义一个命名空间,如下所示xmlns:app="http://schemas.android.com/apk/res-auto"
You should therefore in your top menu tag define a namespace as follows
xmlns:app="http://schemas.android.com/apk/res-auto"
然后使用它来定义你的 showAsAction 属性,就像这样app:showAsAction="ifRoom"
and then use that to define your showAsAction attribute like so
app:showAsAction="ifRoom"
应该可以解决
这篇关于showAsAction=“ifRoom"即使有足够的空间也不显示该项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!