Use of Android--toolbar

Source: Internet
Author: User

Add the following code to the layout file:

 <android.support.v7.widget.Toolbar        android:id="@+id/toobar"        android:layout_width="match_parent"        android:layout_height="?attr/actionBarSize"        android:background="?attr/colorPrimary"> </android.support.v7.widget.Toolbar>

Note: the toolbar in support V7 is used here, and if toolbar is used directly, it is only available on the version of API level 21.

Then add the following code to the topic:

<!--隐藏Actionbar--><item name="windowActionBar">false</item><item name="windowNoTitle">true</item><!--Toolbar的颜色--><item name="colorPrimary">@color/accent_material_light</item>

Add the following code to the activity file:

//使用Toolbar代替ActionbarToolbar toolbar = (Toolbar)findViewById(R.id.toobar);setSupportActionBar(toolbar);

So far, toolbar has replaced Actionbar.
As follows:

Of course there are a lot of ways in toolbar, I'm here to list some of the commonly used:

//设置标题toolbar.setTitle("标题");//设置子标题toolbar.setSubtitle("子标题");//设置Logotoolbar.setLogo(R.mipmap.ic_launcher);//设置导航图标toolbar.setNavigationIcon(R.mipmap.ic_launcher);


Description: Since I was developed using Androidstudio, I use the R.mipmap.ic_lanucher Eclipse students to useR.drawable.ic_lanucher

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use of Android--toolbar

Related Article

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.