Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status bar transparency doesn't work

I am trying to make status bar transparent in my application using this code:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(Color.TRANSPARENT);

But it doesn't work. Status bar just change a color and became grey, not transparent. Where is my mistake? How to make status bar transparent?

like image 932
BArtWell Avatar asked Oct 26 '15 11:10

BArtWell


People also ask

How do I make my status bar white on Android?

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.

How do I customize my Samsung status bar?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.

How do I make the bottom bar transparent on Android?

The simplest way to put a Toolbar transparent is to define a opacity in @colors section, define a TransparentTheme in @styles section and then put these defines in your toolbar.


2 Answers

Try this in your styles.xml(v21)

<name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentStatus">true</item>

Update

You can achieve the same effect programatically on KitKat and afterwards by setting this Window flag

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow(); // in Activity's onCreate() for instance
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

If you set a background resource (like a color or a picture) to your layout, you will see the color or picture "below" the status bar.

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@color/primary_dark</item>

Source

like image 83
Ismael Di Vita Avatar answered Oct 17 '22 11:10

Ismael Di Vita


try calling this from onCreate:

getWindow().getDecorView().setSystemUiVisibility(
    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

getWindow().setStatusBarColor(Color.TRANSPARENT);
like image 22
prat Avatar answered Oct 17 '22 11:10

prat