Search code examples
androidandroid-studiokotlinandroid-layoutnavigation

Android: Bottom Navigation Bar recreating while switching to dark mode


My bottom navigation bar recreates whenever I switch from light mode to dark mode and viceversa. The scenario is this: I'm navigating to a whole new fragment which doesn't have the bottom navigation bar.. now, if I switch from light mode to dark mode, the bottom navigation bar appears when it shouldn't.

How should I deal with it?

Thank you everyone in advance


Solution

  • When the app’s theme changes, App undergoes configuration changes and thus underlying activities recreate themselves.

    Here is what Documentation Says:

    When the app’s theme changes (either through the system setting or AppCompat) it triggers a uiMode configuration change. This means that Activities will be automatically recreated.

    It means if at the start of activity you are setting a fragment that has no bottom navigation bar then you will end up seeing a fragment with no bottom navigation bar after changing the theme. That's what I can say with the little information I have from the question.

    I hope this helps :)