Menu collapsing when using ActionBar tabs for navi

2019-07-07 05:46发布

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条回答
仙女界的扛把子
2楼-- · 2019-07-07 06:46

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.

查看更多
登录 后发表回答