android-BASIC Programming-toolbar

Source: Internet
Author: User

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

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.