Menu collapsing when using ActionBar tabs for navigation

独自空忆成欢 提交于 2019-12-12 12:32:25

问题


I have used ActionBar from the support library to build my application a tabbed navigation bar. 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 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?


回答1:


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

Notice that the showAsAction attribute above uses a custom namespace defined in the tag. 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. So you must use your own namespace as a prefix for all attributes defined by the support library.



来源:https://stackoverflow.com/questions/19660334/menu-collapsing-when-using-actionbar-tabs-for-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!