Items in ActionBarCompat are showed always in Overflow

后端 未结 7 1851
暗喜
暗喜 2021-02-07 06:02

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

I follwed the guide of google developers, but when I test it, the items are sh

相关标签:
7条回答
  • 2021-02-07 06:22
    <item
        android:id="@+id/ok"
        android:icon="@drawable/ic_ok"
        android:orderInCategory="0"
        android:showAsAction="ifRoom"
        android:title="OK"/>
    
    0 讨论(0)
  • 2021-02-07 06:23

    This is also true for the Android Toolbar in new Material Design concepts in the AppCompat-v21 and API levels 21 and above.

    0 讨论(0)
  • 2021-02-07 06:25

    We have two ways to solute this problem.

    1. You need add libs "ActionBarSherlock".This is usage of ActionbarSherlock.

    OR 2. You need add libs "android-Support-v7". If you choice this method ,then your menu.xml need like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:v7="http://schemas.android.com/apk/res-auto" >
    <item
        android:id="..."
        android:icon="..."
        android:showAsAction="always"
        android:title="..."
        v7:showAsAction="always"/>
    </menu>
    
    0 讨论(0)
  • 2021-02-07 06:30

    The question has been updated to include the answer, but for anyone who is interested in the official documentation, see http://developer.android.com/guide/topics/ui/actionbar.html#ActionItems and pay particular attention to the note about using a custom namespace for the showAsAction attribute.

    0 讨论(0)
  • 2021-02-07 06:34

    I had the same problem, and found two solutions:

    In the menu xml (Login.xml), use your app name for the showAsAction tag:

    instead of:

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

    use:

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

    I suppose your application's name is shady.

    the second solution for me, on the activity class, at the onCreateOptionsMenu()

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(
        getMenuInflater().inflate(R.menu.main, menu);
        MenuItem registerMenuItem = menu.findItem(R.id.action_register);
        registerMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); // change this in backcompat
        return true;
    }
    

    if you are using backCompatibility, change last line:

    MenuItemCompat.setShowAsAction(registerMenuItem,MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    
    0 讨论(0)
  • 2021-02-07 06:34

    I think you need to provide the icon for these actions so they can appear in the action bar.

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:shudy="http://schemas.android.com/apk/res-auto" >
    
    <item
        android:id="@+id/action_register"
        android:showAsAction="always"
        android:icon="@drawable/some_icon"
        android:title="@string/login_menu_register" />
    <item
        android:id="@+id/action_register2"
        android:showAsAction="always"
        android:icon="@drawable/some_icon2"
        android:title="miau" />
    
    </menu>
    
    0 讨论(0)
提交回复
热议问题