Android Material design Navigationview side-slip Interface Custom Essays

Source: Internet
Author: User

First, the side-Slip Interface menu customization:

Create a new Activity_main_drawer.xml file under the menu folder, customizing the title and icon:

1<?xml version= "1.0" encoding= "Utf-8"?>2<menu xmlns:android= "Http://schemas.android.com/apk/res/android" >3<group android:checkablebehavior= "single" >4<item android:id= "@+id/nav_forwhy" android:icon= "@drawable/ic_nav_for_why"5android:title= "100,000 Why"/>6<item android:id= "@+id/nav_knowledge" android:icon= "@drawable/ic_nav_knowledge"7Android:title= "Encyclopedia Knowledge"/>8<item android:id= "@+id/nav_expo" android:icon= "@drawable/ic_nav_expo"9Android:title= "Science Expo"/>Ten<item android:id= "@+id/nav_reader" android:icon= "@drawable/ic_nav_reader" OneAndroid:title= "Popular Science books"/> A<item android:id= "@+id/nav_favorite" android:icon= "@drawable/ic_nav_favorite" -Android:title= "My Stash"/> -</group> the  -<item android:title= "Other" > -<menu> -<item android:id= "@+id/nav_author" android:icon= "@drawable/ic_nav_author" +android:title= "Author"/> -<item android:id= "@+id/nav_about" android:icon= "@drawable/ic_nav_about" +android:title= "Copyright note"/> A</menu> at</item> -</menu>

Second, the side-slip interface Header layout customization

Create a new Nav_header_main.xml file under Layout to perform a custom layout of the head-slip interface:

1<?xml version= "1.0" encoding= "Utf-8"?>2 3<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"4 5Android:layout_width= "Match_parent"6 7android:layout_height= "@dimen/nav_header_height"8 9android:background= "@drawable/side_nav_bar"Ten  Oneandroid:paddingbottom= "@dimen/activity_vertical_margin" A  -android:paddingleft= "@dimen/activity_horizontal_margin" -  theandroid:paddingright= "@dimen/activity_horizontal_margin" -  -android:paddingtop= "@dimen/activity_vertical_margin" -  +Android:theme= "@style/themeoverlay.appcompat.dark" -  +android:orientation= "Vertical" A  atandroid:gravity= "Bottom" > -  -  -  -<imageview android:layout_width= "Wrap_content" -  inandroid:layout_height= "Wrap_content" -  toandroid:paddingtop= "@dimen/nav_header_vertical_spacing" +  -android:src= "@mipmap/ic_launcher" the  *Android:id= "@+id/imageview"/> $ Panax Notoginseng  -  the<textview android:layout_width= "Match_parent" +  Aandroid:layout_height= "Wrap_content" the  +android:paddingtop= "@dimen/nav_header_vertical_spacing" -  $android:text= "@string/app_name" $  -Android:textappearance= "@style/textappearance.appcompat.body1"/> -  the  - Wuyi<textview android:layout_width= "Wrap_content" the  -android:layout_height= "Wrap_content" Wu  -Android:text= "Encyclopedia World" About  $Android:id= "@+id/textview"/> -  -  -  A</LinearLayout>

Third, start creating the activity layout file

Add the custom menu and header layouts to the Navigationview control of the Activity_main.xml layout file:
1 <android.support.design.widget.NavigationView  2  3     android:id= "@+id/ Nav_view " 4  5     android:layout_width=" Wrap_content " 6  7     android:layout_ height= "Match_parent" 8  9     android:layout_gravity= "Start"     android:fitssystemwindows= "true"     app:headerlayout= "@layout/nav_header_ Main "     app:menu=" @menu/activity_main_drawer "/>

Iv. Declaration and invocation of Navigationview in activity
1. Declaration Navigationview:
1 Navigationview Navigationview = (navigationview) Findviewbyid (R.id.nav_view);
2, the Navigationview each item's monitoring:
1 @Override2 3  Public Booleanonnavigationitemselected (MenuItem item) {4 5     //Handle Navigation view item clicks here.6 7     intID =Item.getitemid ();8 9 Ten  One     Switch(ID) { A  -          CaseR.id.nav_forwhy://100,000 Why -  the                          Break; -  -          CaseR.id.nav_knowledge://Encyclopedia Knowledge -  +                         Break; -  +          CaseR.id.nav_expo://Science Expo A              Break; at  -          CaseR.id.nav_reader://Popular Science Books -  -                        Break; -  -          CaseR.id.nav_favorite://my stash. in  -                         Break; to  +          CaseR.id.nav_author://author -  the                          Break; *  $          CaseR.id.nav_about://Copyright NoticePanax Notoginseng  -                       Break; the  +     } A  the  +  -Drawerlayout drawer =(drawerlayout) Findviewbyid (r.id.drawer_layout); $  $Drawer.closedrawer (Gravitycompat.start);//Turn off the slide-off interface -  -     return true; the  -}

V. Final:

demo:http://zhushou.360.cn/detail/index/soft_id/3145828

Android Material design Navigationview side-slip Interface Custom Essays

Related Article

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.