app:showAsAction ifRoom is not working on appcompat action bar

前端 未结 6 1998
我寻月下人不归
我寻月下人不归 2020-12-19 04:59

I have an action bar with the following menu items;



        
6条回答
  •  借酒劲吻你
    2020-12-19 05:33

    In my case I had to add a few lines to onCreateOptionsMenu.

    Android Studio didn't let me use android:showAsAction="ifRoom" while using appCompat.

    app:showAsAction="ifRoom" wasn't working and I removed it without problems.

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater  inflater = getMenuInflater();
            inflater.inflate(R.menu.menu, menu);
            for (int i = 0; i < menu.size(); i++) {
                menu.getItem(i).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            }
            return super.onCreateOptionsMenu(menu);
        }
    

提交回复
热议问题