I've made the status and navigation bar go transparent, like so:
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
So that's all good, but now I need some code to make it un-transparent again. Not going good. So I tried using the clearFlags windows function like so:
window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
And then set the status bar color:
window.statusBarColor = ContextCompat.getColor(this, R.color.white)
window.navigationBarColor = ContextCompat.getColor(this, R.color.white)
window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
but the status bar still shows as transparent, is this working for other people. or am I just doing something wrong on my part? Thanks :)
Related
I've made the status and navigation bar go transparent, like so:
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
This works perfectly! But then, when a certain button is tapped, I want it go back to a solid color again with:
window.statusBarColor = ContextCompat.getColor(this, R.color.white)
window.navigationBarColor = ContextCompat.getColor(this, R.color.white)
window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
But the status bar still shows as transparent, is this working for other people? Or am I just doing something wrong on my part? And help would be really appreciated, thank you!
You can clear the window flags on button click like this.
window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
I'm trying to create a ui and running into the problem of the UI not stretching out at the top. Even after I have constrained all the elements and have disabled the action bar.
How do I remove that slightly gray bar at the top and have it be the color of the app itself ?
Any help will be really appreciated.
you can use Theme.MaterialComponents.Light.NoActionBar.Bridge theme on both light and dark themes in android studio now it has two themes for light and dark mode based on user mode so use the above theme on both if you want to make status bar transparent you can use the following snippet
window.apply {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
decorView.systemUiVisibility =
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
statusBarColor = ContextCompat.getColor(context,android.R.color.transparent)
}
window is the one you get from the activity
I'm trying to change the status bar color in a DialogFragment.
However, on some devices, like OnePlus6 (Android 9) it doesn't work.
Furthermore it makes the status bar icons dissapear.
Here's the snippet I'm using:
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = Color.WHITE
Also tried:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
Try this:
getActivity().getWindow().clearFlags(WindowManager.FLAG_FULL_SCREEN);
Where the action bar meets the status bar there is this weird tint or elevation.
Does anyone know where I could find the settings to change it?
Thanks
What it normally looks like:
What it looks like now:
Edit:
I am also running Cyanogenmod 13.
Not sure where its adding that tint, but I was able to set it after it added back to normal
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setElevation(0);
window.setStatusBarColor(getColor(R.color.colorPrimaryDark));
}
I would like to have the statusbar and the navigationbar Translucent on my Main activity, while all the other activities use the Material Design.
What I got so far is this:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
But the result is:
I even tried to set the color to transparent:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(android.R.color.transparent));
window.setNavigationBarColor(getResources().getColor(android.R.color.transparent));
}
But I don't get the graduated shading I'm looking for to make the navigation buttons and the icons on the status bar visible:
Ideas?
I went around the problem.
I created a drawable that simulates the shade I was looking for and put it as wallpaper, while making the status bar and navigation bar transparent:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = this.getWindow();
Drawable background = this.getResources().getDrawable(R.drawable.background);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(getResources().getColor(android.R.color.transparent));
window.setNavigationBarColor(getResources().getColor(android.R.color.transparent));
window.setBackgroundDrawable(background);
}
Here's the result:
From Android Lollipop it is fully translucent, without any shade. So you should do a color like #33000000 to get a shade in the statusbar.
Edit
I think you can only set a color for the statusbar. But you can add an ImageView with a gradient drawable and only show it when you're on lollipop. The status bar is 25dp high. I think there is also an attribute for this, but I don't know it. This way you simulate a gradient in the statusbar.