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

前端 未结 6 1102
日久生厌
日久生厌 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:31

    If you have mDrawerLayout as your drawer layout, you can close it when it is open.

    @Override
    public void onBackPressed() {
        if (this.mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
            this.mDrawerLayout.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }
    

提交回复
热议问题