Android? M. Controls: Toolbar, Tablayout, Navigationview

Source: Internet
Author: User

Tablayout

switching between different views via tab in the app is not a new concept for material design, they are equivalent to the top navigation mode of the home page or the content of different groups within the app , .

The tablayout provides both a fixed tab-average width distribution of the view and a scrollable tab-the view width is not fixed and can be scrolled horizontally.

tabs can be added dynamically in your program:
    tablayout tablayout = (tablayout) Findviewbyid (r.id.tabs);
Tablayout.addtab (Tablayout.newtab (). SetText (TAB1)); Tablayout.addtab (Tablayout.newtab (). SetText (TAB2)); Tablayout.addtab (Tablayout.newtab (). SetText (TAB3));

But most of the time we will not use this, usually the sliding layout will be used in conjunction with Viewpager, so we need Viewpager to help:

Mviewpager = (Viewpager) Findviewbyid (R.id.viewpager);

Set Viewpager data, etc.

Setupviewpager ();

Tablayout tablayout = (tablayout) Findviewbyid (r.id.tabs);

Tablayout.setupwithviewpager (Mviewpager);

By a word setupwithviewpager, we put Viewpager and tablayout together.

Navigationview
Navigationview is very important in MD design, before Google also proposed using Drawerlayout to implement the navigation drawer. This time, in the support library, Google provided navigationview to implement the navigation menu interface .

The most important of these are the two properties:
App:headerlayout
App:menu
with these two properties, we can easily specify the head layout and menu layout of the navigation interface:
<android.support.v4.widget.drawerlayout

http:// Schemas.android.com/apk/res/android

xmlns:app= ' Http://schemas.android.com/apk/res-auto '

Android:layout_width= ' Match_parent '

android:layout_height= ' Match_parent '

Android:fitssystemwindows= ' true ' >

<!--your content layout--

<android.support.design.widget.navigationview

Android:layout_width= ' Wrap_content '

android:layout_height= ' Match_parent '

Android:layout_gravity= ' Start '

app:headerlayout= ' @layout/drawer_header '

app:menu= ' @menu/drawer '/>

</android.support.v4.widget.DrawerLayout>



From for notes (Wiz)

Android? M. Controls: Toolbar, Tablayout, Navigationview

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.