How to show/Hide Navigation Drawer programmatically

前端 未结 4 844
既然无缘
既然无缘 2021-02-02 05:56

How can I use button to show/hide Navigation Drawer, I have used this SO link to create and manage Navigation Drawer.

Now i am using (Swipe to right from left - to show)

4条回答
  •  囚心锁ツ
    2021-02-02 06:41

    If you are using Sliding Drawer Menu, and you want to hide the menu when it is open (when drag from right to left). Then we have to deal with listview object ontouch listener. The code will be like this.

        //((( When we drage from Right to left then menu hide ))))
        lvMenu.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
    
                switch (event.getAction()) 
                {
                    case MotionEvent.ACTION_DOWN:
                        toggleMenu(v);                  
                        break;
    
                    case MotionEvent.ACTION_UP:
                        //showtoast("up");
                        break;
    
                    default:
                        return false;
                }
                return false;
            }
    
    
        });
    
         public void toggleMenu(View v) {
        mLayout.toggleMenu();
    }
    

    For complete code, you can put the comment here, if you have any problem

提交回复
热议问题