Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fitsSystemWindows ignored by ConstraintLayout

I am trying to show make an activity in my app where the statusbar is completely transparent. I added this to my style:

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

But for some reason all views in my are all appearing below the statusbar. All the views are top aligned to parent app:layout_constraintTop_toTopOf="parent".

enter image description here

like image 716
Bart Bergmans Avatar asked Mar 08 '18 15:03

Bart Bergmans


2 Answers

I fixed it by adding the following code to my activity:

Window w = getWindow();
w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
like image 88
Bart Bergmans Avatar answered Sep 23 '22 13:09

Bart Bergmans


Since I wanted to show my layout behind the status bar but still keep the navigation bar the same, this is what worked for me:

Add <item name="android:statusBarColor">@android:color/transparent</item> to my activity theme

Since ConstraintLayout does not seem to respect fitsSystemWindows, wrap it in a CoordinatorLayout.

Add android:fitsSystemWindows="true" to my CoordinatorLayout. Add to my ConstraintLayout

android:fitsSystemWindows="true"
android:clipToPadding="false"
android:clipChildren="false"
like image 21
Orgmir Avatar answered Sep 21 '22 13:09

Orgmir