Update selected state of navigation drawer after back press

后端 未结 6 1154
臣服心动
臣服心动 2021-02-19 22:56

Whats the proper way to handle the selected state of the navigation drawer after back press?

I have a navigation drawer with n entries (in a listview) like the SDK sampl

6条回答
  •  我在风中等你
    2021-02-19 23:36

    This pattern is described in the Implement Back Navigation for Fragments section of the "Proper Back Navigation" documentation.

    If your application updates other user interface elements to reflect the current state of your fragments, such as the action bar, remember to update the UI when you commit the transaction. You should update your user interface after the back stack changes in addition to when you commit the transaction. You can listen for when a FragmentTransaction is reverted by setting up a FragmentManager.OnBackStackChangedListener:

    getSupportFragmentManager().addOnBackStackChangedListener(
        new FragmentManager.OnBackStackChangedListener() {
            public void onBackStackChanged() {
                // Update your UI here.
            }
        });
    

    That would be the proper place to refresh the current option in the navigation drawer.

提交回复
热议问题