"Android" Toolbar

Source: Internet
Author: User

ToolbarBriefly

Toolbar in the v7.21+ package, is a replacement for actionbar components, can be said to be Actionbar upgrade version. There are several features of toolbar compared with Actionbar:

    1. Actionbar belongs to the decorative component of window, one activity can only have one actionbar, but toolbar belongs to the view level, can have any number of
    2. Actionbar customization difficult, toolbar can be regarded as a viewgroup, can be freely paired with

Several compositions of toolbar are similar to those of Actionbar, and the order is:

    1. Navigation buttons
    2. Logo
    3. Title
    4. Custom components
    5. Action menu (Similar menu)
UseReplace Actionbar

If you are using a Compatibility pack, you still have to inherit actionbaractivity, the only point: you need to remove Actionbar from the theme.

<style name= "V7. Toolbar "parent=" Theme.AppCompat.Light.DarkActionBar ">    <item name=" Windowactionbar ">false</item ></style> or <style name= "V7. Toolbar "parent=" Theme.AppCompat.Light.NoActionBar "></style>

Replace Actionbar with toolbar in your code

Setcontentview (R.layout.v7_activity_toolbar);    Toolbar Toolbar = (Toolbar) Findviewbyid (r.id.v7_toolbar_1);    if (Toolbar! = null) {        Setsupportactionbar (toolbar);    }

It's so simple.

Implement tab

It can be noted that the Setnavigationmode method in Actionbar has been marked as deprecated, so it must not be recommended.
Toolbar does not provide a ready-made implementation, although it brings inconvenience, but gives greater freedom.
Just add the tab component to the Custom Components section of toolbar, the tab component is too much, and Google also provides an implementation slidingtablayout.

<android.support.v7.widget.toolbar    android:id= "@+id/v7_toolbar_2"    android:layout_width= "Match_ Parent "    android:layout_height=" 60DP >    < Dev.xesam.android.study.lollipop.v7.toolbar.SlidingTabLayout        android:id= "@+id/v7_sliding_tabs"        Android : layout_width= "match_parent"        android:layout_height= "Wrap_content"/></ Android.support.v7.widget.toolbar>
Implementing NAV List

With tab, replace Slidingtablayout with spinner (older models may need to look for additional components to assist with the desired effect).

<android.support.v7.widget.toolbar    android:id= "@+id/v7_toolbar_1"    android:layout_width= "Match_ Parent "    android:layout_height=" 60DP "    app:theme=" @style/v7. Toolbartheme ">    <spinner        android:id=" @+id/v7_toolbar_spinner "        android:layout_width=" Wrap_ Content "        android:layout_height=" Wrap_content "/></android.support.v7.widget.toolbar>
Demo

Demo (dev.xesam.android.study.lollipop.v7.toolbar.ToolbarActivity)

Android Share Q Group: 315658668

"Android" 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.