mercredi 12 novembre 2014

Android fullscreen/immersive when landscape


Vote count:

0




My fragment host activity looks like this:



<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:local="http://ift.tt/GEGVYd"
android:id="@+id/Content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.DrawerLayout
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">
<FrameLayout
android:id="@+id/ContentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</FrameLayout>


In one of the hosted fragments, I would like it to be full screen (immersive on KitKat+) but only when landscape. The following code is in said fragment and works, although there is a gap between the top of the screen and the content where the action bar would have been.



public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig) {
base.OnConfigurationChanged(newConfig);

var decorView = Activity.Window.DecorView;
var contentView = Activity.FindViewById(Resource.Id.Content);

bool landscape = newConfig.Orientation == Orientation.Landscape;

var newUiOptions = (SystemUiFlags) decorView.SystemUiVisibility;

if (landscape) {
newUiOptions |= SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen | SystemUiFlags.ImmersiveSticky;
}
else {
newUiOptions &= ~(SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen | SystemUiFlags.ImmersiveSticky);
}

contentView.SetFitsSystemWindows(!landscape);

decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;
}


Interestingly removing fitsSystemWindows="true" from the layout works but this needs to be programmatic as the other fragments rely on it. Activity.ActionBar.Hide(), Invalidate() and RequestLayout() calls don't seem to help either.


Thanks!



asked 57 secs ago

Jamie

1,233






Android fullscreen/immersive when landscape

Aucun commentaire:

Enregistrer un commentaire