AppCompat_v7 Toolbar as actionbar not showing 'always' actions from menu, but API Toolbar does

后端 未结 3 1982
囚心锁ツ
囚心锁ツ 2021-02-01 03:05

After 2 days of struggling with the new API 21 Toolbar and appCompat_v7, I think I found a bug on it. If you have 2 actions on your menu like this:



        
3条回答
  •  温柔的废话
    2021-02-01 03:24

    first of all use the app:showAsAction instead of android:showAsAction (like @ianhanniballake) after that in onCreateActionMode after Inflating your menu setShowAsAction in code like this

    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    mode.getMenuInflater().inflate(R.menu.your_menu_name, menu);
    menu.findItem(R.id.your_first_menu_id).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.findItem(R.id.your_second_menu_id).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    return true;
    } 
    

    i had the same problem so after working on it these lines of code works fine for me.

提交回复
热议问题