[Xamarin.Forms]How to make App run in fullscreen in Android?

aluzi liu 486 Reputation points
2021-11-25T10:13:02.627+00:00

I put this code on MainActivity's OnCreate method:

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)  
            {  
                // Kill status bar underlay added by FormsAppCompatActivity  
                // Must be done before calling FormsAppCompatActivity.OnCreate()  
                var statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);  
                if (statusBarHeightInfo == null)  
                {  
                    statusBarHeightInfo = typeof(FormsAppCompatActivity).GetField("_statusBarHeight", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);  
                }  
                statusBarHeightInfo?.SetValue(this, 0);  
            }  
            base.OnCreate(savedInstanceState);  
            this.Window.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.TurnScreenOn);  
  

And I get this:
152574-wpf.png

The status bar is gone, but It still occupies this space, and the page content did not display at fullscreen.
What can I do?

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