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?
More and more businesses are paying attention to ...
According to data from the China Passenger Car As...
Qixi Festival is the most romantic traditional fe...
Dagger and Koin are undoubtedly the two most popu...
2015 is the golden period of rapid development of...
What kind of creative has a high click-through ra...
Editor's note: In order to better promote UI ...
[[424652]] On September 17th, today, Douyin offic...
This super-Earth exoplanet with a fiery surface i...
This article reviews a user addition case in grea...
During the journey of space exploration, astronau...
Audi's plan to form a joint venture with SAIC...
Regarding smartphones, many years ago, Brother Ka...
You can't drink on an empty stomach. I guess ...
© Frederic Cirou/Getty Images Leviathan Press: Re...