Navigationview Study Notes

Source: Internet
Author: User

<Android.support.v4.widget.DrawerLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Android:id= "@+id/drawer_layout"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <!--The main content view -    <includeLayout= "@layout/layout_content" />    <!--The navigetion view -    <Android.support.design.widget.NavigationViewAndroid:id= "@+id/navigationview"Android:layout_width= "Wrap_content"Android:layout_height= "Match_parent"android:layout_gravity= "Start"android:fitssystemwindows= "true"App:headerlayout= "@layout/layout_header"App:menu= "@layout/layout_menu">    </Android.support.design.widget.NavigationView></Android.support.v4.widget.DrawerLayout>

Used to be a ListView, now replaced by navigationview ... Different from the previous steps aside from writing a ListView adapter, there are two properties that can be set

1.app:headerlayout: Add head layout to Navigationview
2.app:menu: Add menu Menu layout to Navigationview

Headerlayout as follows:

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "200DP"Android:background= "@drawable/img1"android:gravity= "Center"android:orientation= "vertical">    <ImageViewAndroid:layout_width= "125DP"Android:layout_height= "125DP"Android:scaletype= "Centercrop"android:src= "@drawable/img" />    <TextViewAndroid:layout_margintop= "15DP"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Blog Park Steve_nash"Android:textcolor= "@android: Color/holo_red_light" /></LinearLayout>

The menu layout is as follows:

<?XML version= "1.0" encoding= "Utf-8"?><Menuxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <GroupAndroid:checkablebehavior= "single"Android:title= "Home items">        <ItemAndroid:id= "@+id/nav_blog"Android:title= "blog address" />        <ItemAndroid:id= "@+id/nav_ver"Android:title= "Version Information" />        <ItemAndroid:id= "@+id/nav_about"Android:title= "About Me" />    </Group>    <ItemAndroid:title= "Sub items">        <Menu>            <ItemAndroid:id= "@+id/sub_exit"Android:title= "Exit App" />            <ItemAndroid:id= "@+id/sub_switch"Android:title= "Toggle Theme" />        </Menu>    </Item></Menu>

You can also add an icon to each item and bother to find it. At this point, you can run and see the effect ...

You can then listen to the Navigationview item's Click event via Setnavigationitemselectedlistener ...

The font color of item in Navigationview and the icon check state color are in the current topic theme

<--font color and icon color in normal state--><Itemname= "Android:textcolorprimary">@android: Color/darker_gray</Item><--Check the status icon color and font Color--> <Itemname= "Colorprimary">@color/accent_material_light</Item>

Of course you can change this state by using the following methods or properties:

Setitembackgroundresource (int): Sets the background resource for the menu, corresponding to the property App:itembackground
Setitemicontintlist (colorstatelist): Sets the color for the menu icon, corresponding to the property app:itemicontint
Setitemtextcolor (colorstatelist): Sets the font color for menu item, corresponding to the property App:itemtextcolor

Reference article:

http://blog.csdn.net/feiduclear_up/article/details/46514791

Navigationview Study Notes

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.