Doubt about hiding status and nav bar

NotCoconutNotCoconut Member ✭✭
edited November 2018 in Xamarin.Forms

I am using the following code to hide the status and navigation bar buttons/options when my app starts, when I swipe up or down to the screen, the buttons appear and seconds later they hide.

    public override void OnWindowFocusChanged(bool hasFocus)
    {
        base.OnWindowFocusChanged(hasFocus);

        int uiOptions = (int)Window.DecorView.SystemUiVisibility;

        Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);

        uiOptions |= (int)SystemUiFlags.LayoutStable;
        uiOptions |= (int)SystemUiFlags.LayoutHideNavigation; 
        uiOptions |= (int)SystemUiFlags.LayoutFullscreen;
        uiOptions |= (int)SystemUiFlags.HideNavigation;
        uiOptions |= (int)SystemUiFlags.Fullscreen;
        uiOptions |= (int)SystemUiFlags.ImmersiveSticky;

        Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
    }

My doubt: is possible to change the time that it takes to hide? or is there a way to keep it hide, ignoring the swipe up and down?

Thank you

Best Answer

  • NotCoconutNotCoconut ✭✭
    Accepted Answer

    @BillyLiu Hi, thanks for your help but it didn't work... I found this:

    IWindowManager manager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast();
    WindowManagerLayoutParams localLayoutParams = new WindowManagerLayoutParams();

            customViewGroup views = new customViewGroup(this);
    
            localLayoutParams.Type = WindowManagerTypes.SystemError;
            localLayoutParams.Gravity = GravityFlags.Top;
            localLayoutParams.Flags = WindowManagerFlags.NotFocusable | 
                                      WindowManagerFlags.NotTouchModal | 
                                      WindowManagerFlags.LayoutInScreen;
            localLayoutParams.Width = WindowManagerLayoutParams.MatchParent;
            localLayoutParams.Height = (int)(35 * Resources.DisplayMetrics.ScaledDensity);
            localLayoutParams.Format = Format.Transparent;
            manager.AddView(views, 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();
    }
    }

    My puttet it on my MainActivity file, now I "disabble" the status bar. I almost forgot... I had tu put this on my AndroidManifestFile:

Answers

  • BillyLiuBillyLiu Member, Xamarin Team Xamurai

    @NotCoconut

    You could use the Theme to hide the status. And it will not show anymore.
    For example:

    <item name="android:windowFullscreen">true</item>
    

    is possible to change the time that it takes to hide?

    You could try to put it in OnCreate().

    or is there a way to keep it hide, ignoring the swipe up and down?

    No, the navigation bar could not ignore the swipe.

  • NotCoconutNotCoconut Member ✭✭
    Accepted Answer

    @BillyLiu Hi, thanks for your help but it didn't work... I found this:

    IWindowManager manager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast();
    WindowManagerLayoutParams localLayoutParams = new WindowManagerLayoutParams();

            customViewGroup views = new customViewGroup(this);
    
            localLayoutParams.Type = WindowManagerTypes.SystemError;
            localLayoutParams.Gravity = GravityFlags.Top;
            localLayoutParams.Flags = WindowManagerFlags.NotFocusable | 
                                      WindowManagerFlags.NotTouchModal | 
                                      WindowManagerFlags.LayoutInScreen;
            localLayoutParams.Width = WindowManagerLayoutParams.MatchParent;
            localLayoutParams.Height = (int)(35 * Resources.DisplayMetrics.ScaledDensity);
            localLayoutParams.Format = Format.Transparent;
            manager.AddView(views, 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();
    }
    }

    My puttet it on my MainActivity file, now I "disabble" the status bar. I almost forgot... I had tu put this on my AndroidManifestFile:

Sign In or Register to comment.