安卓4.3菜单项showAsAction ="总是QUOT;忽视 [英] Android 4.3 menu item showAsAction="always" ignored

查看:177
本文介绍了安卓4.3菜单项showAsAction ="总是QUOT;忽视的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是从Android的4.3(API等级18)开始新的V7 appcompat库中。

I'm using the new v7 appcompat library available starting from Android 4.3 (API level 18).

无论在showAsAction菜单项中指定的内容的,它不显示 - 它始终会溢出菜单图标,并在菜单下把甚至一个菜单项

Regardless of what is specified in showAsAction for a menu item, it's not shown - it always creates the overflow menu icon, and puts even a single menu item under the menu.

尝试添加菜单到这样一个活动:

Trying to add menu to an activity like this:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_sizes, menu);
    return true;
}

这是我的菜单的xml:

And here's my menu xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_add_size"
        android:title="@string/menu_add_item"
        android:orderInCategory="10"
        android:showAsAction="always"
        android:icon="@android:drawable/ic_menu_add" />
</menu>

这是不是新的支持库V7的一个bug,或者只是一些错误的code? 我已经使用了类似于code与ActionBarSherlock很多次了。

Is it a bug of the new support library v7, or just something wrong with the code? I've been using the similar code with ActionBarSherlock many times before.

推荐答案

想通了自己。随着V7的showAsAction支持库应该在这样一个自定义命名空间:

Figured out myself. With the support library v7 the showAsAction should go under a custom namespace like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:balloonberry="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/menu_add_size"
        android:title="@string/menu_add_item"
        android:orderInCategory="10"
        balloonberry:showAsAction="always"
        android:icon="@android:drawable/ic_menu_add" />
</menu>

这篇关于安卓4.3菜单项showAsAction =&QUOT;总是QUOT;忽视的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆