Transparent / transparent status bar and navigation bar

I would like to have a Translucent status bar and navbar in my main activity, while all other activities use material construction.

What I got so far:

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:

enter image description here

I even tried to set the transparency of the color:

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 am not getting the graded shading that I am looking for to display navigation buttons and icons in the status bar:

enter image description here

Ideas?

+3


source to share


2 answers


I got around the problem.

I created a drawable that mimics the shadow I was looking for and put it as wallpaper, making the status bar and navbar 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:

enter image description here

+7


source


With Android Lollipop, it is completely transparent without any shades. So you have to make the color # 33000000 to get the tint in the status bar.

Edit



I think you can set the color for the status bar. But you can add an ImageView with gradient drawing capability and only show it when you are on lollipop. The status bar is 25dp. I think there is an attribute for that too, but I don't know that. This is how you simulate the gradient in the status bar.

+1


source







All Articles