How to close navigation drawer when an item is pressed from it?

前端 未结 6 1118
日久生厌
日久生厌 2021-02-01 11:46

Ideally navigation drawer should get closed once some item has been pressed from it, but its not happening automatically. How to do it ? Thanks!

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-01 12:29

    DrawerLayout mDrawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout)
    
    closeDrawer(); // called when you want to close
    
    public void closeDrawer() {
      if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
        mDrawerLayout.closeDrawer(GravityCompat.START);
      }
    }
    

提交回复
热议问题