hide status bar android

2021-07-02T20:58:33.597+00:00

So I feel kinda dumb asking this but I really am confused right now. I need to hide the status bar when video goes fullscreen but I keep getting

CS0120 An object reference is required for the non-static field, method, or property 'Activity.Window'

I tried making an instance of Activity class but that throws NullReferenceException.

 public class MainActivity : AppCompatActivity, BottomNavigationView.IOnNavigationItemSelectedListener
    {
        WebView web_view;



        public class HelloWebViewClient : WebViewClient
        {
            public override bool ShouldOverrideUrlLoading(WebView view, string url)
            {
                view.LoadUrl(url);
                return false;
            }
        }


        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SupportActionBar.Hide();
            SetContentView(Resource.Layout.activity_main);

            var relativeLayout = FindViewById<RelativeLayout>(Resource.Id.container);
            var relativeLayoutTwo = FindViewById<RelativeLayout>(Resource.Id.containerTwo);
            web_view = FindViewById<WebView>(Resource.Id.webview);
            web_view.Settings.JavaScriptEnabled = true;
            web_view.SetWebChromeClient(new FullScreenClient(relativeLayout, relativeLayoutTwo));




            BottomNavigationView navigation = FindViewById<BottomNavigationView>(Resource.Id.navigation);
            navigation.SetOnNavigationItemSelectedListener(this);
        }

        public class FullScreenClient : WebChromeClient
        {
            readonly FrameLayout.LayoutParams matchParentLayout = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent,
                                                                                                             ViewGroup.LayoutParams.MatchParent);
            readonly ViewGroup content;
            readonly ViewGroup parent;
            View customView;

            public FullScreenClient(ViewGroup parent, ViewGroup content)
            {
                this.parent = parent;
                this.content = content;
            }

            public override void OnShowCustomView(View view, ICustomViewCallback callback)
            {
                customView = view;
                view.LayoutParameters = matchParentLayout;
                parent.AddView(view);
                content.Visibility = ViewStates.Gone;
                **Activity.Window.ClearFlags(WindowManagerFlags.Fullscreen);**
            }

            public override void OnHideCustomView()
            {
                content.Visibility = ViewStates.Visible;
                parent.RemoveView(customView);
                customView = null;

            }
        }
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,921 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 43,931 Reputation points Microsoft Vendor
    2021-07-05T06:44:31.673+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Add following code to your OnCreate method.

       var uiOptions =  
                         SystemUiFlags.HideNavigation |  
                         SystemUiFlags.LayoutHideNavigation |  
                         SystemUiFlags.LayoutFullscreen |  
                         SystemUiFlags.Fullscreen |  
                         SystemUiFlags.LayoutStable |  
                         SystemUiFlags.ImmersiveSticky;  
                   Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;  
    

    111784-image.png

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.