Toolbar Introduction
toolbar is a new navigation control introduced by Android 5.0 to replace the previous Actionbar, due to its high degree of customization, flexibility, material design style and other advantages, more and more applications are also used toolbar, For example, the most commonly used knowledge of the software's top navigation bar is the use of toolbar.
Toolbar Basic Use
Change theme
In order to be able to use toolbar, we need to hide the original Actionbar, this can be modified in the theme, in Res/values/styles.xml to make the following changes:
Add this control to the layout file, with the following code:
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Android. Support.constraint.ConstraintLayout xmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:app= "Http://schemas.android.com/apk/res-auto"4 Xmlns:tools= "Http://schemas.android.com/tools"5 Android:layout_width= "Match_parent"6 Android:layout_height= "Match_parent"7 Tools:context= "Com.contentprovide.liuliu.toolbardemo.MainActivity">8 9 <Android. Support.v7.widget.ToolbarTen Android:layout_width= "Match_parent" One Android:layout_height= "Wrap_content"> A - <TextView - Android:layout_width= "Wrap_content" the Android:layout_height= "Wrap_content" - Android:text= "title bar" /> - - </Android.support.v7.widget.Toolbar> + - </Android.support.constraint.ConstraintLayout>
You can see that I put a TextView control in toolbar, this toolbar is equivalent to a viewgroup. You can customize the title bar style by placing a view inside it.
Run the program, Effect:
To further refine the title bar only need to add the control inside, but also can be added click events to make the function more perfect
Android Toolbar use