How to open Drawer Layout only with button?

后端 未结 4 1577
轻奢々
轻奢々 2020-12-14 13:35

I\'m working on application that has a tab structure, and use sliding movements to move through the tabs.

But now, I want to apply Drawer Layout. The problem is tha

4条回答
  •  借酒劲吻你
    2020-12-14 14:42

    By default the DrawerLayout is initially hidden from the view unless you put a code to open the Drawer, by the time there is a sliding event triggered.

    From the Navigation Drawer example, the contain content_frame is used to dynamically display views inside the Drawer using fragments.

      
        
    

    From the Fragment's onCreateView() you can include a button somewhere that has OnClickListener where in you put this code,

       //For me a better way in avoiding a `null pointer` in getting the DrawerLayout
       final DrawerLayout drawer = (DrawerLayout) getActivity().findViewById(R.id.drawer_layout);
       btn.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                                //Opens the Drawer
                    drawer.openDrawer(Your View, Usually a ListView);
                }
    
                    return false;
            });
    

    You Can also use* to close the drawer.

    drawer.closeDrawer(Your View, Usually a ListView);
    

提交回复
热议问题