how wo immersive in android in .net maui?

mc 5,426 Reputation points
2023-04-08T07:38:24.0833333+00:00

this.Window?.AddFlags(Android.Views.WindowManagerFlags.TranslucentStatus); this.Window?.SetStatusBarColor(Android.Graphics.Color.Transparent); but the status bar is gray not transparent.

Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-04-08T08:17:42.7533333+00:00

    Hello,

    ======Update======================

    You can do this by adding following code in the Oncreate method of MainActivity.cs.

    public class MainActivity : MauiAppCompatActivity 
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
           
            this.Window.SetFlags(WindowManagerFlags.LayoutNoLimits,WindowManagerFlags.LayoutNoLimits);
            this.Window.ClearFlags(WindowManagerFlags.TranslucentStatus);
            this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            this.Window.DecorView.SystemUiVisibility = 0;
    
            this.Window?.SetStatusBarColor(this.Resources.GetColor(Resource.Color.translucent));
        }
    }
    
    

    Then open the Platform/Android/Resources/Values/colors.xml, add this item <color name="translucent">#00000000</color>

    Best Regards, Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.