How to set an icon at the end of Toolbar

后端 未结 5 1449
醉酒成梦
醉酒成梦 2021-01-17 08:36

I want to set an icon at the the end of my Toolbar,which start another activity. My Toolbar portion

 

        
5条回答
  •  时光说笑
    2021-01-17 09:06

    If you want something like this (icon 2) example

    You do not need add icon to the layout manually, you should to implement menu.xml

    1. Create menu.xml like this

      
      
          
      
      
    2. Add it in your activity/fragment to the actionbar/toolbar by

      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
         MenuInflater inflater = getMenuInflater();
         inflater.inflate(R.menu.menu, menu);
         return true;
      }
      
    3. Handle menu items events

    Toolbar with menus works fine, it sets icons to the right of toolbar automatically

提交回复
热议问题