I want a status bar translucent and navigation bar other color not translucent like blue or white
My code
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@color/colorPrimary</item>
</style>
Activity
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
the status bar translucent good but the navigation bar no change color . why ?
navigation bar
Steps to Change the Navigation Bar on Android Smartphone Once you give permissions to the navbar apps, you will be able to use the widgets. On the top, you will get the color widget which adds color to the navigation bar according to the app which is currently opened.
In order to change the hub navigation bar color, we can go to site settings of hub site>Change the look>under the header section>Background> select a theme color to change the background color of your site header.
Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.
Ways to change navigation color:
values-v21/style.xml
<item name="android:navigationBarColor">@color/blue_color</item>
Programatically:
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.primary));
}
check my previous Answer it will definitely help you get the result.
You can achieve this in two ways- either using style or Activity.
values-v21/style.xml
<item name="android:navigationBarColor">@color/navigationbar_color</item>
Using Compat Library in Activity-
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setNavigationBarColor(ContextCompat.getColor(this, R.color.primary));
}
Based on my understanding of "FLAG_LAYOUT_NO_LIMITS" in https://developer.android.com/reference/android/view/WindowManager.LayoutParams.html [Window flag: allow window to extend outside of the screen] the usage of such flag pushes out of the window both the status bar and the navigation bar. In fact using your style.xml file and adding the row
<color name="myWindowBackground">#D7DEB5</color>
to change the white color window background, it is possible to note both the status bar symbols and the navigation bar symbols but not their bars . Moreover using the following code:
int statusBarColor = w.getStatusBarColor();
String hexStatusBarColor = String.format("#%08X", (0xFFFFFFFF & statusBarColor));
int navigationBarColor = w.getNavigationBarColor();
String hexNavigationBarColor = String.format("#%08X", (0xFFFFFFFF & navigationBarColor));
Log.d("FLAGS", "statusBarColor: " + hexStatusBarColor + " -- navigationBarColor: " + hexNavigationBarColor);
you see that the statusBarColor ("#00000000" fully transparent) and the navigationBarColor are correctly set but not shown since out of the window.
Now without using the flag "FLAG_LAYOUT_NO_LIMITS" you get a transparent statusBar (same color as the windowBackground) and as well the wished navigation bar color, but not sure at this point what else the code is trying to get by using this flag.
With FLAG_LAYOUT_NO_LIMITS been set, the view will be extended to status bar and navigation bar, which means you can't set the color by Window.setStatusBarColor. Our App has taken the control of drawing the view behind the navigation bar. We need to set the color on the exactly spot, right behind the navigation bar.
We need to Handle overlaps using insets
by setting padding bottom, you can make the navigation backgroud color by below:
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
val resourceId: Int = resources.getIdentifier("config_navBarInteractionMode",
"integer",
"android")
ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { view, insets ->
val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
if (systemBarInsets.bottom > 0) {
view.setPadding(0,
systemBarInsets.top,
0,
systemBarInsets.bottom)
}
if (resourceId == 0) {
view.setBackgroundColor(Color.LTGRAY)
}
return@setOnApplyWindowInsetsListener insets
}
val windowInsetsControllerCompat = WindowInsetsControllerCompat(window,
window.decorView)
windowInsetsControllerCompat.isAppearanceLightNavigationBars = true
windowInsetsControllerCompat.isAppearanceLightStatusBars = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With