In depth understanding of the toolbar in Android 5.0
Environmental description:
Toolbar introduction
Add in XML layout:
Change the theme to hide the actionbar:
Add the following to the activity Code:
Running effect:
Add background color
Running effect:
Basic attribute settings
Operation effect:
Add options menu
Step 1: create a menu file
The second part rewrites the oncreateoptionsmenu method in the code to load the menu file
Effect:
Personality settings
Left return arrow
To display the built-in return arrow, you need to remove the previously set attribute:
Then add to the code:
Effect:
Overflow icon color
Add to style file:
Effect:
Custom right overflow Icon
Add to the style file:
Running effect:
Change pop-up menu background
To add a style to a style file:
To add a theme to a layout file:
Running effect:
Change pop-up menu text color
Add style file:
Running effect:
Change title text size
Add configuration:
Add style:
Running effect:
The subtitle text size is similar, add the configuration, and then define the style file (omitted here):
Modify pop-up menu location
Modify the configuration so that the pop-up menu appears below the toolbar:
First reset the properties: (in the interface layout file toolbar)
Add to the style file:
Running effect:
event processing
Return button event
Add listening
Menu item click event
override method
Customize Toolbar
You can nest layouts under the toolbar. You can directly put your defined layouts under the toolbar
Toolbar and drawerlayout slide left menu
Add left slide layout file:
Import in main layout file: (under toolbar)
Add association to code:
Running effect:
For the new version of studio, you can select the corresponding template when creating an activity, and the drawerlayout will be automatically created and associated with the toolbar
summary
The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.