How to close Drawer layout on BackPress in Android?

前端 未结 4 760
无人共我
无人共我 2020-12-03 08:09

I press the navigation drawer, then if I press back button, the app exits rather than returning to the previous activity. If I change the xml file, then this problem doesn\'

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 08:57

    ListView mDrawerList;
    
    @Override
    public void onBackPressed() {
    // TODO Auto-generated method stub
    
    if(mDrawerLayout.isDrawerOpen(mDrawerList)){
        mDrawerLayout.closeDrawer(mDrawerList);
    }else{
        super.onBackPressed();
    }
    }
    

提交回复
热议问题