Drawer implementation--

Source: Internet
Author: User

Drawerlayout can achieve the left and right sliding function, as long as the layout file is configured around two drawers can be, about two drawers can be any view, combined with Navigationview can be very good to achieve the function of the side-slide menu

To use Drawerlayout, need v4 package, use Navigationview, need V7 package;

--------------------------------------------Layout------------------------------------------------

<?xml version= "1.0" encoding= "Utf-8"?>
<android.support.v4.widget.drawerlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
xmlns:app= "Http://schemas.android.com/apk/res-auto"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
tools:context= "Com.qianfeng.zhouyi.drawerlayouttest.MainActivity" >

<framelayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"/>

<android.support.design.widget.navigationview
Android:layout_width= "Wrap_content"
android:layout_height= "Match_parent"
Android:layout_gravity= "left"
app:headerlayout= "@layout/layout_navhead"
app:menu= "@menu/mymenu"
Android:id= "@+id/navtest"

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

Drawlayout only needs to configure the Layout_gravity property to "left" or "right" to automatically build the drawer to the ieft or the side, or two to configure

Headerlayout is to add a head layout to the navigation bar.

menu is the selection entry for the corresponding menu item.

--------------------------------------The response operation of the Navigationview--------------------------------------------

To set the Navigationview menu response:

Set the navigation bar Navigationview Click event Navigationview mnavigationview = (navigationview) Findviewbyid (r.id.  Navigation_view); Mnavigationview.setnavigationitemselectedlistener (new Navigationview.onnavigationitemselectedlistener () {    @Override public    boolean onnavigationitemselected ( MenuItem MenuItem) {        switch (Menuitem.getitemid ()) {            //Event action ...        }        Menuitem.setchecked (TRUE);//Click to set it to the selected state        mdrawerlayout.closedrawers ();//close drawer        return true;    });

Drawer implementation--

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.