Ad

Close The Navigation Drawer In The Activity According To A Process In The Fragment?

I have an activity with a navigation drawer menu. I'm make close account process on one of the fragments of this activity. As a result of this process, I send the user to the dashboard. As a result of this, the user's access to the menu should be turned off.Thought that closing the click event of the menu icon would be a solution. I don't know how to do it. Or any other suggestions ?

Ad

Answer

If I get it right you want to disable access to drawer. To do so, you just need to disable button that opens it and lock it when closed. example:

btnMenu.isEnabled = false
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.START)

If you want to access drawer from a fragment, you can't and you don't need.

What you need is a method that performs all operations in your activity and then call this method from your fragment.

Example:

In Activity:

fun closeAndLockDrawer() {
    drawer.closeDrawer(GravityCompat.START);
    btnMenu.isEnabled = false
    drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.START)
}

In Fragment:

(activity as YourActivity).closeAndLockDrawer()
Ad
source: stackoverflow.com
Ad