Showing a menu overflow button in a Toolbar

后端 未结 2 779
遇见更好的自我
遇见更好的自我 2021-01-18 14:00

I\'ve created a Toolbar for Lollipop, but I can\'t seem to figure out how to add an overflow button to the toolbar. I\'m not going to be using the v7 appcompat

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 14:11

    If you want to add the item in the overflow menu you should set never as android:showAsAction. If you set always the item will be an icon in the toolbar.

    Edit your menu.xml like this:

    
    
        
    
    
    

    Also you need to call setActionBar(). Edit initToolbar() like this:

    private void initToolbar() {
        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mToolbar.setTitleTextColor(Color.WHITE);
        mToolbar.setTitle("gnappo");
        mToolbar.showOverflowMenu();
        setActionBar(mToolbar);
    }
    

提交回复
热议问题