Items in ActionBarCompat are showed always in Overflow

后端 未结 7 1850
暗喜
暗喜 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: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:

    
    

    use:

    
    

    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);
    

提交回复
热议问题