Android Actionbardrawertoggle, drawerlayout, ActionBar combined

Source: Internet
Author: User

Actionbardrawertoggle is a switch for opening/closing the drawerlayout drawer


Actionbardrawertoggle provides a convenient way to match drawerlayout and Actionbar to achieve the recommended drawer function. Click Actionbar's Home button 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 (), indicating that the actionbardrawertoggle is synchronized with the Drawerlayout state


About Drawerlayout not much to say, please go here http://blog.csdn.net/jjwwmlp456/article/details/38682637


The overall effect, need to support ACTIONBAR,SUPPORT-V7 package Compat in Actionbaractivity can inherit, 3.0 can also be used in the theme of direct use. No more talking.


Several of the main 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 automatically associated with the Actionbar, the picture of the switch is displayed on the action, if not set, can also have the effect of the drawer, but the default icon} /** Menu Key Click event Handling */@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

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.