I have an Activity
which is displayed fullscreen. This works perfectly with many layouts I have tried, except for when the CoordinatorLayout
is the roo
You may try removing android:fitsSystemWindows="true"
from ImageView, and change onResume()
like this:
@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);
}
The mRootView.setFitsSystemWindows(false);
is important for fitting child views into full screen.
Without this call, the layout would appear as if the status bar and navigation bar still exists. As shown in the picture below:
Screenshot without setFitsSystemWindows(false)
And with this call:
Screenshot with setFitsSystemWindows(false)
The reason, I think, is that when fitsSystemWindows
is true, the CoordinatorLayout
will reserve space for status bar and navigation bar in order to work with other widgets which draw background of bars themselves. But when we hide the System UI bars, there is no need to reserve space, and thus we need to tell CoordinatorLayout
to release the spaces for other child views.
Following is the layouts in the screenshot
Layout for the activity:
The fragment in the screenshots above:
Hope this helps.