1

I am trying to hide statusbar and notification in fullscreen mode. User should not be able to pull/swipe down status/notification bar in Xamarin android.

In native android it is working fine with below property (android version 8.0).

View decorView = getWindow().getDecorView(); 
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);

getWindow().setFlags(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);

Equivalent to TYPE_APPLICATION_OVERLAY in xamarin not able to get.

Any solution for Xamarin.Android?

I have tried below properties for xamarin:

View decorView = Window.DecorView;
    var uiOptions = (int)decorView.SystemUiVisibility;
    var newUiOptions = (int)uiOptions;      
    newUiOptions |= (int)SystemUiFlags.HideNavigation;
    newUiOptions |= (int)SystemUiFlags.LayoutHideNavigation;
    newUiOptions |= (int)SystemUiFlags.LayoutFullscreen;
    newUiOptions |= (int)SystemUiFlags.Fullscreen;
    newUiOptions |= (int)SystemUiFlags.ImmersiveSticky; 
    decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

    Window.AddFlags(WindowManagerFlags.TranslucentNavigation);
    Window.AddFlags(WindowManagerFlags.TranslucentStatus);
    Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);
halfer
  • 19,824
  • 17
  • 99
  • 186
Rahul Baradia
  • 11,802
  • 17
  • 73
  • 121

3 Answers3

0

Changing the window flags in OnCreate to fullscreen should do the trick

 this.Window.AddFlags(WindowManagerFlags.Fullscreen); //to show
 this.Window.ClearFlags(WindowManagerFlags.Fullscreen); //to hide

Revert in case it doesn't work.

Update:

        if ((int)Android.OS.Build.VERSION.SdkInt >= 19)
        {
            var decorView = this.Window.DecorView;
            decorView.SystemUiVisibility = StatusBarVisibility.Hidden;// (StatusBarVisibility)newUiOptions;
        }
        else
        {
            var attrs = this.Window.Attributes;
            attrs.Flags |= WindowManagerFlags.Fullscreen;
            this.Window.Attributes = attrs;
        }
FreakyAli
  • 13,349
  • 3
  • 23
  • 63
0

This code used to generate a view to overlay the statusBar area, but not sure if it work on Oreo.

Requires SYSTEM_ALERT_WINDOW Permission.

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        SetContentView(Resource.Layout.Main);

        WindowManagerLayoutParams localLayoutParams = new WindowManagerLayoutParams();

        localLayoutParams.Type = WindowManagerTypes.SystemError;
        localLayoutParams.Gravity = GravityFlags.Top;
        localLayoutParams.Flags = WindowManagerFlags.NotFocusable | 
            WindowManagerFlags.NotTouchModal | WindowManagerFlags.LayoutInScreen;
        localLayoutParams.Width = WindowManagerLayoutParams.MatchParent;
        localLayoutParams.Height = (int)(50 * Resources.DisplayMetrics.ScaledDensity);
        localLayoutParams.Format = Format.Transparent;

        IWindowManager manager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
        customViewGroup view = new customViewGroup(this);

        manager.AddView(view, localLayoutParams);
    }
    public class customViewGroup : ViewGroup
    {
        public customViewGroup(Context context) : base(context)
        {
        }
        public override bool OnTouchEvent(MotionEvent ev)
        {
            return true;
        }
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            // throw new NotImplementedException();
        }
    }

Hope this helps.

original Java code source:https://stackoverflow.com/a/25397029/3814729

Mohamed Krayem
  • 418
  • 8
  • 19
0

after trying various combinations I solved the problem in this way

    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        Window.AddFlags(WindowManagerFlags.Fullscreen);
        Window.AddFlags(WindowManagerFlags.LayoutNoLimits);
        Window.AddFlags(WindowManagerFlags.LayoutInScreen);
        Window.ClearFlags(WindowManagerFlags.ForceNotFullscreen);

        base.OnCreate(savedInstanceState, persistentState);
    }

Style file:

<style name="Application.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>