'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 1:[1]

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 :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Muhammad waris