2

Description:

This is a question that had been made on this site but answers were not helpful for me. I need to make ONLY the status bar transparent and this is what i found:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}

I´ve tried it and it works but it makes transparent the bottom action bar too (With bottom baction bar i mean this:)

enter image description here

How can i do to make ONLY the top status bar transparent?

Thanks so much for reading

Tomas M
  • 287
  • 4
  • 16

2 Answers2

1

You can check my answer on this post, as it seems like it is exactly what you are looking for.

Would hate to type it all here again but the answer from @Yunus might not work if all conditions are not met, mainly what the documentation for statusBarColor tells you.

The color for the status bar. If the color is not opaque, consider setting {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and {@link android.view.View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}. For this to take effect, the window must be drawing the system bar backgrounds with {@link android.R.attr#windowDrawsSystemBarBackgrounds} and the status bar must not have been requested to be translucent with {@link android.R.attr#windowTranslucentStatus}. Corresponds to {@link android.view.Window#setStatusBarColor(int)}.

Refer the answer for setting those required flags and style, also to keep navigation bar simply DO NOT add View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION flag in case you have it in some code.

Good Luck.

ljk
  • 1,496
  • 1
  • 11
  • 14
0

You can create a custom theme that sets the status bar color. It works on version 21 and up:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
         <!-- You can customize it by changing statusBarColor. -->
        <item name="android:statusBarColor">@color/pieces_cherry</item>
</style>

And in your manifest you need to set this as your app theme

Yunus Kulyyev
  • 1,022
  • 15
  • 26