Toolbar is introduced in Android 5.0 to replace the ActionBar control. It can be highly customized and flexible to use. The official Toolbar must be used in systems above 5.0. If you need to use it in a lower version, you need to use the Toolbar in the support v7 package. Next is the introduction of Toolbar on the official website:
Prerequisites To use ToolBar, you need to hide the ActionBar of the activity. So how to hide it? There are three methods. The following are introduced respectively Method 1: Modify in the res/values/styles.xml file
You can also use the theme without ActionBar directly
Method 2: Modify the theme of the specified activity in the manifest file as follows:
Method 3: Cancel it directly in the code. Before setContentView.
How to use Add the following code in the layout file. The position is not fixed.
title is used to set the title. subtitle is used to set the subtitle. titleTextColor is used to set the title font color. background is used to set the background color. The effect is as follows: These values can also be set dynamically in Java code.
Add Menu To add a menu, we first need to have a menu. Here I choose to create main.xml in res/menu/ to define the menu file. The code is as follows
Below is the code in java file.
Display Icon in Menu After writing this, we will find that the hidden menu does not display the icon, so how do we set it: Just re-do the method: The activity here is AppCompatActivity
The effect is as follows: |
<<: Android development SMS verification code example
>>: How do IT staff manage user application experience in a complex environment?
The continued growth of Chinese companies and the...
Is user growth like falling in love? It's ind...
Around 3:50 pm on January 9, two Chinese female t...
Smart homes allow us to see and feel more and mor...
An inflatable doll, as the name suggests, is an i...
Due to the epidemic this year, many Internet comp...
Now, they hope to create more innovative car desi...
From 2016 to this year, it is the third year for ...
Nowadays, many companies have their own WeChat off...
Following the release of the first developer beta...
At CVPR (the world's top academic conference ...
Apple has launched the "Apple SIM" pro...
There are many articles about how TikTok reached ...
Sometimes, the difference between people is that ...
The fragmentation of the Android system has alway...