Android 3.0 Android pushed ActionBar this control, and by the Year 2013 (4.0) Google began to aggressively push the so-called Android style,material design.
Toolbar Actionbar Differences in toolbar can be changed in any position.
Toolbar layout:
Setnavigationicon
That is, the icon for the Up button is set, because the Material interface, in toolbar here the UP button style is not in the past ActionBar oh.
Setlogo
The APP's icon.
Settitle
The main title.
Setsubtitle
Subtitle.
Setonmenuitemclicklistener
Sets the action of the menu buttons.
1. Create a new toolbar reference.
<Android.support.v7.widget.ToolbarAndroid:layout_width= "Match_parent"Android:layout_height= "50DP"Android:layout_alignparentbottom= "true"Android:layout_marginbottom= "10DP"Android:id= "@+id/toolbar"Android:theme= "@style/zcx"Android:background= "@color/coloraccent"></Android.support.v7.widget.Toolbar>
2. Reference toolbar in the code
= (Toolbar) Findviewbyid (R.id.toolbar);
It is set to remove the window title to show toolbar. It is similar to Actionbar.
3. Set menu and click events
Toolbar.inflatemenu (R.menu.main);//Set the Fill menu in the upper-right corner//Click eventsToolbar.setonmenuitemclicklistener (NewToolbar.onmenuitemclicklistener () {@Override Public BooleanOnmenuitemclick (MenuItem item) {Switch(Item.getitemid ()) { Caser.id.action_settings://........ CaseR.id.action_refresh://........} toast.maketext (Getapplicationcontext (),"Zcx", Toast.length_short). Show (); return true; } });
4. Set Theme Style
<style name= "zcx" parent= "Theme.AppCompat.Light.NoActionBar" > <item name= "Actionoverflowbuttonstyle" > @style/actionbutton.overflow.zhihu</item> </style> <style name= " ActionButton.Overflow.ZhiHu "parent=" Android:style/widget.holo.light.actionbutton.overflow "> <item Name= "ANDROID:SRC" > @drawable/icon</item> </style>
Defines the Theme.AppCompat.Light.NoActionBar of toolbar theme inheritance and changes the background image of overflow.
5. Effect (toolbar position let me move bottom)
android-BASIC Programming-toolbar