Material Design (iv)--navigationview

Source: Internet
Author: User

The navigation drawer can be a very important focus for in-app identification and navigation, and the consistency of the design can have an important impact on how the app is navigated, especially for small white users. Navigationview makes this idea easier to implement by providing a framework. This framework satisfies your need for navigation drawers and the ability to populate navigation item with the menu resource.

You can use Navigationview as a drawerlayout drawer content view in the layout file like this:

1<Android.support.v4.widget.DrawerLayout2 xmlns:android= ' http://schemas.android.com/apk/res/android '3 Xmlns:app= ' Http://schemas.android.com/apk/res-auto '4 Android:layout_width= ' match_parent '5 Android:layout_height= ' match_parent '6 Android:fitssystemwindows= ' true '>7<!--Your content layout -8<Android.support.design.widget.NavigationView9 Android:layout_width= ' wrap_content 'Ten Android:layout_height= ' match_parent 'android:layout_gravity= ' Start 'App:headerlayout= ' @layout/drawer_header 'App:menu= ' @menu/drawer '/> -</Android.support.v4.widget.DrawerLayout>

You may notice the two properties of Navigationview: App:headerlayout controls an optional layout for the header. App:menu is a menu resource for populating navigation items, and it is also possible to update the contents of a navigation item at run time. Navigationview provides you with the gauze protection of the status bar to ensure that Navigationview interacts accurately with the status bar on the device of the API 21+.

The simplest drawer menu is a collection of a series of checkable menu items:

1<GroupAndroid:checkablebehavior= ' single '>2<Item3 Android:id= ' @+id/navigation_item_1 '4 android:checked= ' true '5 Android:icon= ' @drawable/ic_android '6 Android:title= ' @string/navigation_item_1 '/>7<Item8 Android:id= ' @+id/navigation_item_2 '9 Android:icon= ' @drawable/ic_android 'Ten Android:title= ' @string/navigation_item_2 '/> One</Group>

The checked item will be highlighted in the navigation drawer to ensure that the user knows which navigation item is selected in the current situation.

You can also use subheader in the menu to split the group of navigation items:

1<Item2 Android:id= ' @+id/navigation_subheader '3 Android:title= ' @string/navigation_subheader '>4<Menu>5<Item6 Android:id= ' @+id/navigation_sub_item_1 '7 Android:icon= ' @drawable/ic_android '8 Android:title= ' @string/navigation_sub_item_1 '/>9<ItemTen Android:id= ' @+id/navigation_sub_item_2 'Android:icon= ' @drawable/ic_android 'Android:title= ' @string/navigation_sub_item_2 '/> -</Menu> -</Item>

You can use the Setnavigationitemselectedlistener () method to set Onnavigationitemselectedlistener to get callbacks for the selected item. It provides you with the clicked MenuItem to allow you to handle the selected event, change the selected state, load new content, close the drawer through the code, or any event you want.

Material Design (iv)--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.