Navigation drawer doesn't close

后端 未结 11 947
暖寄归人
暖寄归人 2021-02-08 03:44

The navigation drawer in my app is not closing. I am using activities instead of fragments. When i click on any item in the listview, it opens other activities as i

相关标签:
11条回答
  • 2021-02-08 04:21
    private DrawerLayout mDrawerLayout;
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.closeDrawers();
    

    it works

    0 讨论(0)
  • 2021-02-08 04:22

    Try

    drawer.closeDrawer(Gravity.START);

    Your drawer gravity is start so Use that to close the corresponding drawer

    0 讨论(0)
  • 2021-02-08 04:28

    Call

    drawer.closeDrawer(navList);
    

    in onItemClick() method

    0 讨论(0)
  • 2021-02-08 04:31

    Here is the code: Lets say you have the drawer class

    in your activity call the class as and make a vaiable and assign it(put the drawer layout within a fragment for smoother user experience)

    Drawer drawer;
    drawer = (Drawer)getActivity().getSupportFragmentManager().findFragmentById(R.id.theid);
    drawer.mDrawerLayout.closeDrawer(Gravity.END);
    //End for right and Start for left
    

    Hope it helps

    0 讨论(0)
  • 2021-02-08 04:32

    I didn't see any code where you are closing the ListView from drawer... close the ListView Drawer on ListItem click...

        navList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int pos,long id){
                drawer.closeDrawer(navList);
                switch (pos){
                    case 0:
                        Intent i = new Intent(MainActivity.this,Aluminium.class);
                        startActivity(i);
                        break;
                    case 1:
                        Intent i2 = new Intent(MainActivity.this,Gold.class);
                        startActivity(i2);
                        break;
                    case 2:
                        Intent i3 = new Intent(MainActivity.this,Zinc.class);
                        startActivity(i3);
                        break;
                }
            }
        });
    
    0 讨论(0)
提交回复
热议问题