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