Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent status bar not working with windowTranslucentNavigation="false"

I am developing an Activity where I need to make the navigation bar opaque, and the status bar transparent on devices running 5.0+ (API 21+). The styles I am using are below, along with an explanation of my problem.

AppTheme extends Theme.AppCompat.Light.NoActionBar

<item name="android:statusBarColor">@color/transparent</item> <item name="android:windowActionBar">false</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item> <item name="android:statusBarColor">@color/welbe_red_transparent</item> 

FullscreenTheme extends AppTheme

<item name="android:windowNoTitle">true</item> <item name="android:statusBarColor">@color/transparent</item> <item name="android:windowTranslucentNavigation">true</item> 

This makes the app look like this

android:windowTranslucentNavigation="true"

If I remove the android:windowTranslucentNavigation style, or set it to false in Fullscreen, it fixes the navigation bar issue. The problem is the status bar turns completely white instead of staying transparent and displaying the content behind it.

android:windowTranslucentNavigation="false"

I have tried using fitsSystemWindow="true" in my layouts, but it didn't fix the issue. Anyone know why this is happening?

like image 520
Austyn Mahoney Avatar asked Feb 03 '15 00:02

Austyn Mahoney


People also ask

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 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.

What is Android Statusbar?

Status bar (or notification bar) is an interface element at the top of the screen on Android devices that displays the notification icons, minimized notifications, battery information, device time, and other system status details.


1 Answers

android:windowTranslucentNavigation does one thing that android:statusBarColor doesn't do, which is requesting the SYSTEM_UI_FLAG_LAYOUT_STABLE and SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN flags.

These are the ones that you need to request in order to draw behind the status bar.

Request them in the onCreate of your Activity:

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

Alternatively you can also simply set your apps theme background and that will also pop up behind your status bar.

More information here.

like image 58
Jeroen Mols Avatar answered Oct 13 '22 11:10

Jeroen Mols