How to access the displayCutout (safe Area) on Android in Xamarin Forms

Danilo 1 Reputation point
2020-11-23T19:58:07.22+00:00

Hey,

we are developing a game based on skiasharp and Xamarin Forms. The SKCanvasView is in a Grid in and setup as fullscreen. To use the notch area we inplemented the following piece of code in the MainActivity of the Android project:

Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;

The point is, we have a user interface on top of the SKCanvasView which should use the Safe Area Insets. How can we access these Safe Area Insets for Android devices?

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

2 answers

Sort by: Most helpful
  1. LandLu-MSFT 21 Reputation points
    2020-11-24T03:21:03.01+00:00

    Hello,

    Welcome to Microsoft Q&A!

    If you want to use the space of the status bar, add the code below in the main activity on Android:

    protected override void OnCreate(Bundle savedInstanceState)  
    {  
        TabLayoutResource = Resource.Layout.Tabbar;  
        ToolbarResource = Resource.Layout.Toolbar;  
      
        base.OnCreate(savedInstanceState);  
      
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);  
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);  
                  
        LoadApplication(new App());  
      
        StatusBarVisibility option = (StatusBarVisibility)SystemUiFlags.LayoutFullscreen | (StatusBarVisibility)SystemUiFlags.LayoutStable;  
        Window.DecorView.SystemUiVisibility = option;  
        Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);  
        Window.SetStatusBarColor(Android.Graphics.Color.Transparent);  
    }  
       
    
     
    

    Thank you.


    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.

    0 comments No comments

  2. Danilo 1 Reputation point
    2020-11-24T14:16:41.427+00:00

    Thanks for the respond.

    Maybe I explained the problem the wrong way around. We are using your posted piece of code already and it works fine. It shows the SKCanvasView in the status bar area. But how can we take care, that the user interface (Labels and Button) are not in the notch area?

    Because some of the phones we are testing on (e.g. Samsung Galaxy A70) have round corners and a notch in the status bar. How can we figure out how big this notch is by using Xamarin Forms?

    I hope our problem makes more sense now.
    And thanks for the help.

    0 comments No comments