9

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

Bart Bergmans
  • 4,061
  • 3
  • 28
  • 56

2 Answers2

7

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);
Bart Bergmans
  • 4,061
  • 3
  • 28
  • 56
  • 5
    This only works in your case because you want the navigation bar transparent as well. If somebody only wants the status bar to be transparent, it won't work for them. – Afzal N Oct 01 '18 at 14:42
2

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"
Orgmir
  • 383
  • 3
  • 8
  • `android:fitsSystemWindows="true"` is actually respected by `ConstraintsLayout`. Wrapping the `ConstraintLayout` with a `CoordinatorLayout` isn't needed. – Archie G. Quiñones Apr 12 '19 at 01:08
  • Also, if you only added `@android:color/transparent` and not `true`, you don't even have to added `android:fitsSystemWindows="true"` – Archie G. Quiñones Apr 12 '19 at 01:11
  • Well, this is what worked for me. I'll add my full theme config later! – Orgmir Apr 12 '19 at 01:54
  • Yeah. This would work but what I'm saying is that you added way more than what you needed. The comment was for everyone else who'll take a look at this post in the future. – Archie G. Quiñones Apr 12 '19 at 02:50
  • Well, after your comment I went ahead and removed the CoordinatorLayout, but I can't make it work that way. ConstraintLayout doesn't stretch under the status bar. – Orgmir Apr 12 '19 at 04:43