Package com. demo. usher. demo_slidingmenu; Import android. OS. Bundle; Import android. support. v4.widget. DrawerLayout; Import android. support. v7.app. ActionBarDrawerToggle; Import android. support. v7.app. AppCompatActivity; Import android. support. v7.widget. Toolbar; Import android. view. View; Import android. widget. AdapterView; Import android. widget. ArrayAdapter; Import android. widget. ImageView; Import android. widget. LinearLayout; Import android. widget. ListView; Import java. util. ArrayList; Import java. util. List; Import butterknife. BindView; Import butterknife. ButterKnife; Public class MainActivity extends AppCompatActivity { @ BindView (R. id. tbHeadBar) Toolbar mTbHeadBar; /* Slide menu Layout */ @ BindView (R. id. llMenu) LinearLayout mLlMenu; /* Slide menu ListView placement menu item */ @ BindView (R. id. lvMenu) ListView mLvMenu; @ BindView (R. id. ivContent) ImageView mIvContent; @ BindView (R. id. dlMenu) DrawerLayout mMyDrawable; ActionBarDrawerToggle mToggle; Private List <String> lvMenuList = new ArrayList <String> (){{ Add ("angry "); Add ("happy "); Add ("sad "); Add ("embarrassed "); }}; Private List <Integer> imageList = new ArrayList <Integer> (){{ Add (R. drawable. angry ); Add (R. drawable. happy ); Add (R. drawable. sad ); Add (R. drawable. embarrassed ); }}; @ Override Protected void onCreate (Bundle savedInstanceState ){ Super. onCreate (savedInstanceState ); SetContentView (R. layout. activity_main ); ButterKnife. bind (this ); /* Initialize Toolbar and DrawableLayout */ InitToolBarAndDrawableLayout (); MLvMenu. setAdapter (new ArrayAdapter (this, android. R. layout. simple_expandable_list_item_1, lvMenuList )); MLvMenu. setOnItemClickListener (new AdapterView. OnItemClickListener (){ @ Override Public void onItemClick (AdapterView <?> Parent, View view, int position, long id ){ MIvContent. setImageResource (imageList. get (position )); MMyDrawable. closeDrawers ();/* Hide drawer */ } }); } Private void initToolBarAndDrawableLayout (){ Setsuppactionactionbar (mTbHeadBar ); /* The following two methods are used to set the available return key */ Getsuppactionactionbar (). setHomeButtonEnabled (true ); Getsuppactionactionbar (). setDisplayHomeAsUpEnabled (true ); /* Set title text not to be displayed */ Getsuppactionactionbar (). setDisplayShowTitleEnabled (false ); MToggle = new ActionBarDrawerToggle (this, mMyDrawable, mTbHeadBar, R. string. open, R. string. close ){ @ Override Public void onDrawerOpened (View drawerView ){ Super. onDrawerOpened (drawerView ); // Toast. makeText (MainActivity. this, R. string. open, Toast. LENGTH_SHORT). show (); } @ Override Public void onDrawerClosed (View drawerView ){ Super. onDrawerClosed (drawerView ); // Toast. makeText (MainActivity. this, R. string. close, Toast. LENGTH_SHORT). show (); } }; /* MMyDrawable. setDrawerListener (mToggle); not recommended */ MMyDrawable. addDrawerListener (mToggle ); MToggle. syncState ();/* synchronization status */ } } |