The openDrawer () and closeDrawer () Methods of DrawerLayout, drawerlayout
The following code
DrawerLayout mdrawerLayout;
Button btn;
The Declaration component is above, which is omitted in other simple processes.
Btn. setOnClickListener (new OnClickListener (){
MdrawerLayout. openDrawer (Gravity. LEFT); // the direction set here should be the same as the gravity direction in the xml file below. Otherwise, an error will be reported. Both start and LEFT appear from the LEFT.
MdrawerLayout. closDrawers (); // No parameter is set. Close all the drawers that appear.
});
----------------------------------------------------- The following is drawerLayout. xml ----------------------------------------------------------------------
<? Xml version = "1.0" encoding = "UTF-8"?>
<Android. support. v4.widget. DrawerLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/dl_left"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<! -- The remaining layout of the main interface is as follows -->
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Hello World"/>
</LinearLayout>
<! -- Layout after the drawer is opened, that is, the layout of the ListView -->
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: background = "# fff"
Android: orientation = "vertical"
Android: gravity = "center"
Android: layout_gravity = "start">
<ListView
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: id = "@ + id/lv_left_menu"
Android: divider = "@ null">
</ListView>
</LinearLayout>
</Android. support. v4.widget. DrawerLayout>