Android: Bottom Navigation Bar recreating while switching to dark mode - android

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

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

If you are using android:background on your BottomNavigationView, change it to app:itemBackground

Related

How to implement system bars insets with edge-to-edge gesture navigation?

I'm trying to add the edge-to-edge stuff for the gesture navigation bar to the Tip Time app from Google. I added the transparent navigationBarColor XML tag to themes.xml as well as the following code to the onCreate() function of MainActivity.kt:
This was directly copy-pasted from the documentation. Android Studio says that "it cannot find a parameter with this name" for each of the three margins. I noticed that changing the parenthesis right after <ViewGroup.MarginLayoutParams> to curly braces fixes the compiler error. Maybe the documentation is just wrong?
Anyways, even after fixing that, the app still doesn't look right:
As you can see, the entire view gets shifted up slightly and the "Cost of Service" TextView is partially cut-off by the app bar. What would I need to change to implement the system/navigation bar insets for edge-to-edge content so the UI looks nice? Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
As per documentation for edge to edge contents:
Draw behind the status bar if it makes sense for your content and
layout, such as in the case of full-width imagery. To do this, use
APIs such as AppBarLayout, which defines an app bar pinned to the top
of the screen.
So, while handing the window insets (especially the top one), you can't use the default ActionBar, instead you need to customize that with AppBarLayout and ToolBar, and to make it act as the ActionBar, use setSupportActionBar(), and a NoActionBar app theme; it'd be <style name="Theme.TipTime" parent="Theme.MaterialComponents.DayNight.NoActionBar"> in the shared repo.
the entire view gets shifted up slightly and the "Cost of Service" text field is partially cut-off by the app bar.
The reason that the sample uses the default ActionBar instead of a customized one; when it comes to handle the top window insets, it won't affect the default ActionBar; notice that you pass in the activity's root layout to setOnApplyWindowInsetsListener callback, and as the ActionBar is not a part of the activity, it won't be affected. Therefore the activity is shifted up behind the ActionBar when the top inset is removed. So, to solve this you have either to totally remove the default ActionBar or to use a custom toolbar instead.
Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
Use a transparent status bar color in the app's theme:
<item name="android:statusBarColor" tools:targetApi="l">#android:color/transparent</item>

UI bug for the light theme (Fragment)

I've created a new project in Android Studio and there is a UI bug for the interface and I am not able to fix it. I don't understand what is this problem.
Basically it appears a top margin / a top padding for the fragment. In the "night theme" the problem is not present and the only thing I change between light and night is colours (in styles>themes)...
I explain a moment the structure of my project: there is the main activity, which contains "Nav_menu" and the "Fragment" view. This problem is present is all the fragments, so I thought it was a problem in Main... but I cannot understand actually.
I set manually 0dp to padding and margin, but nothing changes... do any others got this problem?
Let me show some images:
I think you use theme action bar set to be true, In every fragment action bar or title bar is showing because fragment is opening through an activity, try to set false for action bar or whatever in style theme

PreferenceFragment changing ActionBar

I have an app that has a navigation drawer throughout the app. I've just added a Preferences Activity with a nested PreferenceScreen.
All works well on the main screen, but when I click into the nested screen, the ActionBar defaults to the Android back button, completely removing the context/overflow menu as well the navigation drawer. I'm sure it has something to do with the fragments being replaced, but all my efforts to fix it have done nothing.
How can I have the PreferenceFragment maintain my normal action bar?
Thanks

Setting Navigation Icon on Android ActionBar

So I'm working on adding ActionBarSherlock and the Navigation Drawer to a project that previously implemented a custom (very poorly written) "action bar". Instead of using fragments and a backstack of activities for navigation, some activities show and hide different layouts. (That is, suppose I am in a list mode and then select a button to go into an edit screen. The app currently hides the list layout and shows another layout.).
So I've added actionbar sherlock and a navigation drawer to all the activities. I want to be able to programmatically switch the navigation icon from the 3 lines to the arrow when certain buttons are pressed.
I can't figure out how to do this though. Any ideas?
Thanks!
The solution to this problem is to use the method:
setDrawerIndicatorEnabled(boolean enable)
inside the ActionBarDrawerToggle class.
After:
drawer.setDrawerListener(toggle);
Use this code:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.select);
It depends how wedded you are to built-in actionbar artifacts. You can always redraw the current actionbar by inflating a layout of your choosing, then calling
getSherlockActivity().getSupportActionBar().setDisplayShowTitleEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowHomeEnabled(false);
getSherlockActivity().getSupportActionBar().setDisplayShowCustomEnabled(true);
// Inflate and do whatever you need to your view...
getSherlockActivity().getSupportActionBar().setCustomView(abView);
getSherlockActivity().getSupportActionBar().show();
When you want to go back to your standard (assuming you're using a DrawerLayout to do your navigation drawer), you can just set make a call to setDisplayShowCustomEnabled(false) (re-enable showHome and showTitle as you please).
As far as I know, customization of the back button can only be done via themes. Besides, swapping the drawer icon for the back icon (within the same Activity) doesn't make sense, since users would still be able to access the navigation drawer by sliding the left most edge to the right. It just wouldn't make sense.
If you absolutely need the back icon, then it would make the most sense to make that screen a new Activity since you would indeed be adding another "level" to the stack, which is what the back icon represents.

Briefly hiding ActionBar without resizing Activity

I'm using a ViewPager to scroll between different fragments. There are two types of fragments, using two different menu resources. I'm invalidating the menu to switch between those resources when necessary. That's all working pretty well, but the menu is "redrawn" without an animation.
To prevent having to mess with individual MenuItems I was hoping I could briefly hide the ActionBar while the new menu is loaded, showing it when that's done. That's working as expected as well, but the activity is resized when the ActionBar is toggled.
Is there any way to prevent this from happening, or otherwise hide the ugly transition between menu resources?
I didn't quite catch the menu part of your problem, but there is an easy solution to preventing your activity from resizing when the ActionBar appears or disappears.
You can tell the ActionBar to draw itself in overlay mode, meaning it will float on top of the activity, in stead of actually being part of the activity's layout. Use either android:windowActionBarOverlay in your theme, or the Window.FEATURE_ACTION_BAR_OVERLAY flag from code.
You probably want to use this feature in conjunction with the actionBarSize constant, that specifies the correct offset for the first view in your layout. This way, your content still appears below the ActionBar, but since the ActionBar itself is an overlay, upon hiding/showing it, the activity will not resize.
<SomeView
...
android:layout_marginTop="?android:attr/actionBarSize" />
More details can be found in the documentation.

Categories

Resources