Ruocco
Ruocco

Reputation: 573

Translucent/Tansparent status bar and navigation bar

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:

enter image description here

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:

enter image description here

Ideas?

Upvotes: 4

Views: 4449

Answers (2)

Ruocco
Ruocco

Reputation: 573

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:

enter image description here

Upvotes: 9

Kevin van Mierlo
Kevin van Mierlo

Reputation: 9814

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.

Upvotes: 1

Related Questions