菜单项不会在动作条显示 [英] Menu items doesn't show up on the actionbar

查看:130
本文介绍了菜单项不会在动作条显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用appcompat在我的应用程序。我想要的菜单项显示在动作条或至少溢出(3个点),以显示他们的时候没有房间。有很多的动作条的空间,但他们仍然没有显示出来。菜单流程提出了从底部,而且也只有在菜单按钮为pressed。

I am using appcompat in my app. I want the menu items to show on actionbar or at least the overflow(3 dots) to show them when there is no room. There is lot of space on the actionbar, but still they don't show up. The menu flow raises from the bottom and that too only when menu button is pressed.

menu_activity.xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/menu_lang"
        android:showAsAction="always"
        android:title="@string/menu_lang"
        android:icon="@android:drawable/ic_input_lang"/>

</menu>

活动:

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

帖子说,这不是在硬件菜单按钮为present作品。但是,其他应用程序都能够表现出同样的设备上的项目。所以,这个问题的答案似乎是不正确的。是否有人可以在这方面的帮助?

This post says that it not works when hardware menu button is present. But other apps are able to show items on the same device. So, that answer seems to be incorrect. Can someone please help on this?

推荐答案

您似乎使用了错误的菜单: 您的文件被命名为menu_activity.xml和你膨胀与资源编号菜单: R.menu.reminder_menu

You seem to be using the wrong menu: Your file is named "menu_activity.xml" and you inflate the menu with the Resource-Id: R.menu.reminder_menu

菜单的资源名称应该是相同的文件名,例如: R.menu.manu_activity

The Resource name of the menu should be the same as the file name, i.e.: R.menu.manu_activity

本再试一次 - 我遇到了这一点,一旦它驱使我坚果...

Try it with this again - I ran into this too once and it drove me nuts...

更新 澄清的是,上述部分是为混淆后,请确认:

Update After clarification that the above part was for obfuscation, please make sure that:

  1. 您延长ActionBarActivity。
  2. 您使用(或扩展)的Theme.AppCompat主题活动的一个(或整个应用程序)
  3. 因为旧设备时,动作条相关的属性不是present,确保在XML中,所有这些属性都使用自定义命名空间。在这里,这将是 showAsAction 属性,使兼容性库可以接他们回家。
  1. You extend ActionBarActivity.
  2. You use (or extend) one of the Theme.AppCompat themes for the activity (or whole app)
  3. Because on older devices, the Actionbar related attributes are not present, make sure that all these attributes in the XML are used with a custom namespace. Here that would be the showAsAction attribute, so that the compatibility library can pick them up.

您已经有定义的自定义命名空间(应用程序,在菜单标签)。您需要修改安卓showAsAction 标记应用程序:showAsAction 根据Android的指南

You already had the custom namespace defined ("app", in the menu tag). You need to change the android:showAsAction tag to app:showAsAction according to the Android guide.

您纠正menu_activity.xml将如下所示:

Your corrected menu_activity.xml would then look like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/menu_lang"
        app:showAsAction="always"
        android:title="@string/menu_lang"
        android:icon="@android:drawable/ic_input_lang"/>

</menu>

href="http://developer.android.com/guide/topics/ui/actionbar.html">扩展Android的指南的动作条的

The extended Android guide for actionbar covers these new and nasty traps...

这篇关于菜单项不会在动作条显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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