Is there any way to change the color of the navigation bar BUTTONS not the navigation bar itself from white to grey:
to
you can do this in API > 21 as follow :
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.some_color));
}
see more information here
or just add following code in values-v21/style.xml
<item name="android:navigationBarColor">#color/theme_color</item>
Related
I am trying to transparent navigation bar and status bar on Android 13 and below version. But getting different result.
Here what suggested in latest android dev event:
themes.xml
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
MainActivity.kt
WindowCompat.setDecorFitsSystemWindows(window, false)
But I am getting result like this in Android 13 and Android 8 version:
Am I missing something? Thank you.
Well, this is an intended behavior. The BottomNavigationView is respecting the bottom navigation bar space, and the bottom navigation bar has a transparent background, it's just that the root layout has a white background.
You can either:
Make the app full screen, so the bottom of the BottomNavigationView neglects the windows insets calculated by bottom navigation bar size, or...
You can change the color of the navigation bar to match the color of the BottomNavigationView so it can look like one view
I want to change the color of the system navigation bar icon color but could only succeed to change the navigation bar background color, using these codes programmatically:
<item name="android:navigationBarColor">#color/black</item>
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.navigationBarColor = resources.getColor(R.color.primary_text_color)
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION //For setting material color into black of the navigation bar
}
Thanks in advance.
I have a problem with SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR somehow not working, but SYSTEM_UI_FLAG_LIGHT_STATUS_BAR is working. I'm working with Android API 28 at the moment.
So whats happening? On API 23 and below I get translucent Status Bar and Navigation Bar as expected. Between API 23 and API API 26 I get transculent Navigation Bar and Light Mode Status bar as expected. But on API 27 and above I get the Light Mode Status Bar but not the Light Mode Navigation Bar. It just is the normal black one and nothing changes.
Here is my MainActivity with my code to enable Translucent or Light Mode Status Bar and Navigation Bar based on the Android API Level (Note my comments describe what works and what doesn't):
View decorView = getWindow().getDecorView();
Window win = getWindow();
//Setup Status Bar and Nav Bar white if supported
if(Build.VERSION.SDK_INT >= 27) {
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);// <- works not
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); // <- works
}
else if (Build.VERSION.SDK_INT >= 23 && Build.VERSION.SDK_INT < 27) {
//this here works
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
win.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
} else {
//this here works
win.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
win.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
And this here is my style.xml:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorWhite</item>
<item name="colorPrimaryDark">#color/colorWhite</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:textColorPrimary">#color/colorBlack</item>
<item name="android:fitsSystemWindows">true</item>
</style>
</resources>
Can you guys tell me what's missing? I use the exact same code for Navigation bar as I do for the Status Bar but only the Status Bar gets Light Mode. Thanks for every help
After hours of testing I figured it out! First you have to set your Navigation Bar to white in xml with target API above 26 in your style.xml:
<item name="android:navigationBarColor" tools:targetApi="27">#android:color/white</item>
After that you have to import this flag in your Main Activity:
import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
And in your Code you have to set the flags all toghether like this:
if(Build.VERSION.SDK_INT >= 27) {
decorView.setSystemUiVisibility(FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
And now if Im above API 26 I get Light Nav and Status Bar!
In your code NAVIGATION_BAR flag is getting override by STATUS_BAR Flag.
To add both the flag replace.
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
With
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
Update:
You can also specify the Color of the NavigationBar
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.primary));
I know I can use colorPrimary to determine the color of Toolbar, and colorPrimaryDark to determine the color of Status bar.
I'm using the following theme
<!-- Base application theme. -->
<style name="Theme.Noteplus.Base.Brown" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimaryLight</item>
<item name="colorPrimaryDark">#ff0000</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
One of the interesting attribute is, when I slide out the navigation menu, the status bar becomes transparent automatically.
During run-time, sometime I would like to change the color of status bar.
setTitle("Recycler bin");
toolbar.setBackgroundColor(Color.BLUE);
getWindow().setStatusBarColor(Color.parseColor("#5694FF"));
It will looks as follow
Unfortunately, calling setStatusBarColor, will also loss the transparency attribute of status bar, when we slide out the navigation menu.
May I know, how to change status bar color during run-time, without lossing its transparency attribute? For my case, after I changing the status bar to blue during run-time, when I slide out navigation drawer, I wish to see status bar transparency attribute being retained.
Update
I had tried
private void setStatusBarColor(int color) {
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(color);
}
}
It doesn't help to provide transparency attribute when the navigation drawer slides out.
You are using a DrawerLayout. That means, that instead of using Window#setStatusBarColor(int) you should be using one of DrawerLayout#setStatusBarBackground() overloads.
The equivalent of your code is following:
ColorDrawable colorDrawable = new ColorDrawable(0xFF5694FF);
drawerLayout.setStatusBarBackground(colorDrawable);
I've applied minor changes to the template app that can be created with Android Studio wizard:
I guess your problem with transparency is not about the method you are using but its rather about the color itself!
You are using this getWindow().setStatusBarColor(Color.parseColor("#5694FF"));
Try to use RGBA instead of RGB so make it transparent, should be something like this:
getWindow().setStatusBarColor(Color.parseColor("#5694FF80"));
private void changeStatusBarColor(String color){
if (Build.VERSION.SDK_INT >= 21) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.parseColor(color));
}
}
If you check here in stack overflow everyone before that line of code set the transparency of the status bar to solid with
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
I'm trying to change the color of the bottom navigation bar.
It supposed to be super easy using xml, I've added this lines in values/styles:
<item name="android:navigationBarColor" tools:targetApi="lollipop">#color/navigationBarColor</item>
V21:
<item name="android:navigationBarColor">#color/navigationBarColor</item>
Also tried programatically:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.navigationBarColor));
}
The navigation bar color won't change. I have a viewpager with 2 fragments, each fragment has a recyclerview in it. My device running Android 7.
Any ideas?