Actionbardrawertoggle is a switch. For opening/closing the drawerlayout drawer
Actionbardrawertoggle provides a convenient way to match drawerlayout and Actionbar. To implement the recommended drawer function.
Click Actionbar Homebutton to eject the drawerlayout drawer.
Use it in the two callback functions in the activity:
Onconfigurationchanged
onoptionsitemselected
Call Actionbardrawertoggle.syncstate () in the activity's onpostcreate (). Indicates that the Actionbardrawertoggle is synchronized with the Drawerlayout state and the drawer icon in the Actionbardrawertoggle. Icon for Home-button set to Actionbar
About Drawerlayout not much to say, please go here http://blog.csdn.net/jjwwmlp456/article/details/38682637
In this official example, the content of this article has been implemented.
The overall effect, need to support Actionbar. SUPPORT-V7 package of Compat in Actionbaractivity can inherit, 3.0 can also be used in the theme of the direct use of the way. No more talking.
A few basic function calls
Actionbardrawertoggle mdrawertoggle;drawerlayout mdrawerlayout;void init () {Mdrawerlayout.setdrawerlistener (new Mydrawerlistener ());//Set drawer switch listener Mdrawertoggle = new Actionbardrawertoggle (activity, Mdrawerlayout, R.drawable.ic _drawer, R.string.drawer_open, r.string.drawer_close);} After/** activity is created, */@Overrideprotected void onpostcreate (Bundle savedinstancestate) {super.onpostcreate ( savedinstancestate) mdrawertoggle.syncstate ();//The method will be associated with the Actionbar itself, and the picture of the switch is displayed on the action. Suppose not set, can also have the effect of drawer, just is the default icon}/** menu key Click event Processing */@Overridepublic Boolean onoptionsitemselected (MenuItem item) {return Mdrawertoggle.onoptionsitemselected (item) | | super.onoptionsitemselected (item);} /** Device Configuration changes */@Overridepublic void onconfigurationchanged (configuration newconfig) {super.onconfigurationchanged ( Newconfig); mdrawertoggle.onconfigurationchanged (newconfig);} /** Drawer Monitor */private class Mydrawerlistener implements Drawerlayout.drawerlistener {@Overridepublic void ondraweropened (View Drawerview) {//Open DrawermdrawertogGle.ondraweropened (Drawerview);//switch status to opened} @Overridepublic void ondrawerclosed (View drawerview) {// Turn off drawermdrawertoggle.ondrawerclosed (Drawerview);//switch status to Closed} @Overridepublic void Ondrawerslide (View Drawerview, float Slideoffset) {///drawer Sliding callback Mdrawertoggle.ondrawerslide (Drawerview, slideoffset);} Callback mdrawertoggle.ondrawerstatechanged @Overridepublic void ondrawerstatechanged (int newstate) {//Drawer state Change ( newstate);}}
Android Actionbardrawertoggle, drawerlayout, ActionBar combined