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?
Whether it is the BAT giants or emerging startups...
The Zhejiang Provincial Museum houses several anc...
Today I’m going to share with you a guide to avoi...
According to the information released by the Stat...
Recently, the local epidemic in Dongguan has been...
Everyone knows about Douyin now. Many celebrities...
What’s the matter with many places announcing the...
How to better disseminate information/products? T...
The concept of growth hacking has been very popul...
I will use Amap, Zhihu , LeTV, etc. as examples t...
gossip Nowadays, more and more people are aware o...
On April 14 and 15, the 2018 Honda Industry-Unive...
Among the many ways to find customers, telephone ...
Qianchuan has fully opened up the delivery of sea...
The twenty-third day of the twelfth lunar month T...