Android Toolbar use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.