Toolbar conflict in the system comes inflateMenu return key (setDisplayHomeAsUpEnabled) and Toolbar itself

  In the Toolbar APP can set inflateMenu in the upper right corner to add a menu bar, but at the same time I want to use the system comes with the return key on the left side, and with it creates a problem: inflateMenu the upper right corner will not take effect, that is no menu button to get access to information the following solutions:

If you are calling setSupportActionBar() 
you don’t need to use toolbar.inflateMenu()
 because the Toolbar is acting as your ActionBar. 
All menu related callbacks are via the default ones. 
The only time you need to call toolbar.inflateMenu() is when you are using the Toolbar as a standalone widget.

That is not in use at the time of use inflateMenu

setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

But the two lines of code is used to add the system comes back key, so this is the case there is no way to use both, but that adjustment following code sequence will be useful, but it is not, ultimately, to use another method to add return button:

setNavigationIcon

This is a small icon in the upper left corner to add toolbar

This way you can avoid conflicting issues, but should not be stupid like me, have to use a toolbar, and a system that comes with it. . . . . . . .

 



Guess you like

Origin www.cnblogs.com/heiyang/p/10993183.html