Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:fitsSystemWindows not working

Tags:

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> 

Screenshot

like image 951
Taig Avatar asked Jan 29 '15 01:01

Taig


People also ask

Does Android fitssystemwindows work with child views?

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.

Does fitssystemwindows = True Move content under status bar?

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.

What is the purpose of fitssystemwindows?

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

Why fitssystemwindows = true works for coordinatorlayout but doesn't for framelayout?

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.


1 Answers

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"> 
like image 200
Ali Karaca Avatar answered Sep 18 '22 16:09

Ali Karaca