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?
How did I make 10 million in sales from 4 live br...
168.2 billion. Alibaba achieved its Double Eleven...
What is the price of Lijiang Auto Mini Program ag...
A cup of coffee a day seems to be the standard fo...
□ Li Chuanfu On May 8, EMR, a well-known market r...
In the Triassic period, ichthyosaurs, pinnipeds a...
Do you need logical thinking when writing copy ? ...
The "Notice on the Management of Mobile Game...
If you are already a very good programmer, but st...
The artist's concept above shows stars, black...
After I used text messages to activate lost custo...
Ask a question I have come into contact with many...
For website SEO optimization personnel, providing...
The above person is right, it depends on the size...
Today, we will explain in detail how to increase ...