我想获得的动作条上的我的应用程序工作正常(我使用ActionBarSherlock得到的Android 2.x和4.x版之间的一个统一的用户界面)。
我觉得安卓showAsAction =ifRoom
只是一个又大又肥的谎言。每当我设置一个动作 ifRoom
它总是显示在溢出菜单,即使有空间足够了。下面是来自同一个仿真器两个截图。第一次显示了设置为所有选项动作条永远
第二显示了最后两个选项设置为 ifRoom 。正如你所看到的,是房PLENTY时,他们都在
总是
截图所示,那么为什么不把它们都在第二展示,因为他们确实有房间吗?
下面是我的menu.xml文件:
< XML版本=1.0编码=UTF-8&GT?;
<菜单的xmlns:机器人=http://schemas.android.com/apk/res/android>
<项目
机器人:ID =@ + ID /加
机器人:图标=@可绘制/ ic_menu_btn_add
机器人:showAsAction =总是
机器人:标题=添加/>
<项目
机器人:ID =@ + ID / calculateNPV
机器人:图标=@可绘制/ menu_icon_npv
机器人:showAsAction =总是
机器人:标题=NPV/>
<项目
机器人:ID =@ + ID / calculateIRR
机器人:图标=@可绘制/ menu_icon_irr
机器人:showAsAction =总是
机器人:标题=IRR / YR/>
<项目
机器人:ID =@ + ID /发送
机器人:图标=@机器人:可绘制/ ic_menu_share
机器人:showAsAction =总是
机器人:标题=@字符串/ share_pdf/>
<项目
机器人:ID =@ + ID /图
机器人:图标=@可绘制/ ic_menu_gallery
机器人:showAsAction =ifRoom
机器人:标题=@字符串/ view_cashflow_diagram/>
<项目
机器人:ID =@ + ID / deleteReorder
机器人:图标=@可绘制/ ic_menu_clear_playlist
机器人:showAsAction =ifRoom
机器人:标题=@字符串/ delete_reorder_cashflows/>
< /菜单>
解决方案
我希望我不是太晚来参加聚会。
这真的不是一个大胖子的谎言,但一个小的疏忽。
在 showAsAction
属性必须使用不同的命名空间http://schemas.android.com/apk/res-auto
![发现 编辑精选 空间作品 室内设计](https://p.xsw88.cn/allimgs/daicuo/20230912/4943.png)
您应该因此,在顶部菜单标签定义命名空间如下
的xmlns:程序=http://schemas.android.com/apk/res-auto
,然后用它来定义,像这样的showAsAction属性
应用程序:showAsAction =ifRoom
这应该修复它
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).
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?
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.
The showAsAction
attribute must be defined using a different namespace "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"
and then use that to define your showAsAction attribute like so
app:showAsAction="ifRoom"
That should fix it
相关推荐
最新文章