How to display both icon and title of action inside ActionBar?

前端 未结 10 2040
庸人自扰
庸人自扰 2020-11-29 18:08

I need to display both icon and title of action inside ActionBar.

I\'ve tried \"withText\" option, but it has no

10条回答
  •  佛祖请我去吃肉
    2020-11-29 18:55

    Some of you guys have great answers, but I found some additional thing. If you want create a MenuItem with some SubMenu programmatically:

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
    
            SubMenu subMenu = menu.addSubMenu(0, Menu.NONE, 0, "Menu title");
            subMenu.getItem().setIcon(R.drawable.ic_action_child);
            subMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    
            subMenu.add(0, Menu.NONE, 0, "Subitem 1");
            subMenu.add(0, Menu.NONE, 1, "Subitem 2");
            subMenu.add(0, Menu.NONE, 2, "Subitem 3");
    
            return true;
        }
    

提交回复
热议问题