You can try to remove android:fitsSystemWindows="true" from ImageView and change onResume() as follows:
@Override protected void onCreate(Bundle savedInstanceState) { .... mRootView = (CoordinatorLayout) findViewById(R.id.coordinatorLayout); .... } public void hideBars() { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY); mRootView.setFitsSystemWindows(false); }
mRootView.setFitsSystemWindows(false); It is important to set the user's views in full screen.
Without this call, the layout will look like the status bar and navigation bar still exist. As the picture below:
Screenshot without setFitsSystemWindows (false)
And with this call:
Screenshot with setFitsSystemWindows (false)
I think the reason is that when fitsSystemWindows true, CoordinatorLayout reserve a place for the status bar and navigation bar to work with other widgets that paint the background of the bars themselves. But when we hide the bars in the system interface, there is no need to reserve space, and therefore we need to tell CoordinatorLayout to free up spaces for other child views.
Below are the layouts in the screenshot
Layout for this operation:
<android.support.design.widget.CoordinatorLayout android:id="@+id/coordinatorLayout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/black" android:fitsSystemWindows="true" tools:context="org.hamster.carz.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <include layout="@layout/frag_container"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" android:src="@mipmap/car_add" /> </android.support.design.widget.CoordinatorLayout>
Fragment in the screenshots above:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="horizontal"> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="2" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginBottom="2dp" android:layout_weight="1" android:background="@drawable/controller_button"/> <Button android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="2dp" android:layout_weight="1" android:background="@drawable/controller_button"/> </LinearLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="12dp" android:layout_weight="1"> <android.support.design.widget.FloatingActionButton android:id="@+id/fab_disconnect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margin="@dimen/fab_margin" android:src="@mipmap/ic_clear" app:backgroundTint="@color/colorAccentDark"/> </FrameLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="2" android:orientation="vertical"> <Button android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginBottom="2dp" android:layout_weight="1" android:background="@drawable/controller_button"/> <Button android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="2dp" android:layout_weight="1" android:background="@drawable/controller_button"/> </LinearLayout> </LinearLayout>
Hope this helps.
source share