First look at the effect
Use the latest android-support-v4.jar
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> ... <!-- The navigation drawer --> <ListView android:id="@+id/left_drawer" android:layout_width="120dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" android:divider="@android:color/transparent" android:dividerHeight="0dp" android:background="#EEA9B8"/> </android.support.v4.widget.DrawerLayout>
/* Drawer navigation variable */private drawerlayout mdrawerlayout; private listview mdrawerlist; private actionbardrawertoggle mdrawertoggle ;... /* drawer navigation related */mdrawerlayout = (drawerlayout) findviewbyid (R. id. drawer_layout); mdrawerlist = (listview) findviewbyid (R. id. left_drawer); mdrawerlayout. setdrawershadow (R. drawable. draw, gravitycompat. relative_horizontal_gravity_mask); mdrawerlist. setadapter (New simpleadapter (this, Getdraweritems (false), R. layout. drawer_item, new string [] {"drawer_img", "drawer_title"}, new int [] {R. id. drawer_img, R. id. drawer_title}); mdrawerlist. setonitemclicklistener (New draweritemclicklistener (); mdrawertoggle = new actionbardrawertoggle (this,/* Host activity */mdrawerlayout,/* drawerlayout object */R. drawable. draw,/* nav drawer image to replace 'up' caret */R. string. search_labe L,/* "open drawer" Description for accessibility */R. string. defalut_text/* "Close drawer" Description for accessibility */) {public void ondrawerclosed (view) {getactionbar (). settitle ("ondrawerclosed"); invalidateoptionsmenu (); // creates call to onprepareoptionsmenu ()} public void ondraweropened (view drawerview) {getactionbar (). settitle ("ondraweropened"); invalidateoptionsmenu (); // C Reates call to onprepareoptionsmenu () }}; mdrawerlayout. setdrawerlistener (mdrawertoggle );... /*** listens to the drawer navigation item Click Event */private class draweritemclicklistener implements listview. onitemclicklistener {@ override public void onitemclick (adapterview <?> Parent, view, int position, long ID) {selectitem (view, position) ;}} private Boolean flag = false; private void selectitem (view, int position) {If (position = 0) {If (! Flag) {mdrawerlist. setadapter (New simpleadapter (this, getdraweritems (true), R. layout. drawer_item, new string [] {"drawer_img", "drawer_title"}, new int [] {R. id. drawer_img, R. id. drawer_title}); flag = true;} else {mdrawerlist. setadapter (New simpleadapter (this, getdraweritems (false), R. layout. drawer_item, new string [] {"drawer_img", "drawer_title"}, new int [] {R. id. drawer_img, R. id. drawer_title}); flag = false ;}} else {textview Title = (textview) view. findviewbyid (R. id. drawer_title); string cityname = title. gettext (). tostring (); this. cityinput. settext (cityname );}}
For more information, see my translation http://blog.csdn.net/lc19850921/article/details/8982315.