ActionBarCompat 中的项目始终显示在溢出中 [英] Items in ActionBarCompat are showed always in Overflow

查看:16
本文介绍了ActionBarCompat 中的项目始终显示在溢出中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用 ActionBarCompat,我想在操作栏中显示一两个项目

I'm using ActionBarCompat in my app, an I want to show one or two items in the action bar

我遵循了 google 开发人员的指南,但是当我对其进行测试时,这些项目会显示在溢出"选项中(在 Nexus 4 中),并且如果我点击菜单按钮(如果存在)(例如 Galaxy S3)

I follwed the guide of google developers, but when I test it, the items are showed in the "Overflow" option (in Nexus 4) and if I tap on the menu button if there exist (ex. Galaxy S3)

我做错了什么?

找到解决方案

您可以在答案中找到它.

You can find it in a answer.

推荐答案

我找到了解决方案,所以我发布了答案:

I found the solution so I posted as Answer:

找到解决方案

在菜单的 xml 中,您必须放置新的命名空间,以使 actionbarcompat 工作.所以有一些选项需要这个空间名而不是android".所以解决方案是这样的:

In the xml of the menu, you have to put the new namespace, to make actionbarcompat work. So there are some options that need this spacename instead of "android". So the solutions is This:

旧的登录菜单:

    <item
        android:id="@+id/action_register"
        android:showAsAction="always"
        android:title="@string/login_menu_register"/>

新建登录菜单(解决方案)(看看如何调用showAsAction")

    <item
        android:id="@+id/action_register"
        shudy:showAsAction="always"
        android:title="@string/login_menu_register"/>

Login.xml (菜单)

<item
    android:id="@+id/action_register"
    android:showAsAction="always"
    android:title="@string/login_menu_register"/>
<item
    android:id="@+id/action_register2"
    android:showAsAction="always"
    android:title="miau"/>

登录Activity.java

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SLog.d(CLASS_NAME + " onCreate()");
        setContentView(R.layout.activity_login);
        actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        findViews();
        buttons();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.login, menu);
        return true;
    }

清单

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >
        <activity
            android:name="com.shudy.myworld.LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

这篇关于ActionBarCompat 中的项目始终显示在溢出中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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