In my theme I defined the following rules to draw my views behind the status bar:
<item name="android:statusBarColor">@android:color/transparent</item> <item name="android:windowDrawsSystemBarBackgrounds">true</item>
And in the Activity (onCreate):
getWindow.getDecorView.setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN )
Then, in my View im using a Barcodescanner that is supposed to draw behind the status bar, which is working. However when I apply the android:fitsSystemWindows
to any child view they don't get their position adjusted. It's working when I apply it to the root element, though.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <my.Scanner android:id="@+id/scanner" android:layout_width="match_parent" android:layout_height="match_parent" /> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <!-- Should receive a top padding, right? --> <View android:layout_width="50dp" android:layout_height="50dp" android:background="@color/red" /> </FrameLayout> </FrameLayout>
However when I apply the android:fitsSystemWindows to any child view they don't get their position adjusted. It's working when I apply it to the root element, though.
The first thing you need to know that fitsSystemWindows = true doesn’t move your content under the status bar. However, it works though for some layouts like CoordinatorLayout, DrawerLayout because they override the default behavior.
That’s what the default behavior of the android:fitsSystemWindows="true" attribute gives you: it sets the padding of the View to ensure the contents don’t overlay the system windows. A few things to keep in mind: fitsSystemWindows is applied depth first — ordering matters: it’s the first View that consumes the insets that makes a difference
Let’s check why fitsSystemWindows = true works for CoordinatorLayout and doesn’t work for FrameLayout and how to fix it. The first thing you need to know that fitsSystemWindows = true doesn’t move your content under the status bar.
Use CoordinatorLayout as root for your view, it worked for me.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With