简体   繁体   English

使用ActionBar选项卡进行导航时菜单折叠

[英]Menu collapsing when using ActionBar tabs for navigation

I have used ActionBar from the support library to build my application a tabbed navigation bar. 我已经使用支持库中的ActionBar来构建我的应用程序标签导航栏。 I have two tabs in my application. 我的应用程序中有两个选项卡。 Both of these Fragments have menus and they have one menu item and I'd like to show it as an action in the action bar, but for some reason the overflow icon is shown instead of the icons assigned to these items. 这两个片段都有菜单,它们有一个菜单项,我想在操作栏中将其显示为一个动作,但由于某种原因,会显示溢出图标而不是分配给这些项目的图标。 They are shown as text under the dropdown menu. 它们在下拉菜单下显示为文本。

My XML looks the following. 我的XML看起来如下。

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/my_id"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:icon="@drawable/ic_action_new"
        android:title="New"/>
</menu>

What's wrong? 怎么了?

As you're using the activities from the compatibility package, make sure that you use the proper namespaces when building the menu item( link ). 当您使用兼容包中的活动时,请确保在构建菜单项( 链接 )时使用正确的命名空间。 Here's a note from the guide to the menu item implementation: 以下是菜单项实施指南中的注释:

Using XML attributes from the support library 使用支持库中的XML属性

Notice that the showAsAction attribute above uses a custom namespace defined in the tag. 请注意,上面的showAsAction属性使用标记中定义的自定义命名空间。 This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. 在使用支持库定义的任何XML属性时,这是必需的,因为旧设备上的Android框架中不存在这些属性。 So you must use your own namespace as a prefix for all attributes defined by the support library. 因此,您必须使用自己的命名空间作为支持库定义的所有属性的前缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM