How to remove space from the top of a splash screen in Xamarin.Forms?

334 Views Asked by At

I'm working on an application with Xamarin.Forms in Visual Studio 2019, I already have the splash screen but when I run it it doesn't cover the entire screen, it leaves a space where the notification bar should go, I already tried with the "NoTileBar" property and it did, but when opening it from the smartphone does not make the change. Could you help me change it?

Styles.xml

    <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowBackground">@drawable/splash_screen</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowActionBar">true</item>
</style>

enter image description here

2

There are 2 best solutions below

0
Dinesh Falwadiya On BEST ANSWER

styles.xml

  <style name="MainTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
   <item name="android:windowBackground">@drawable/splash_screen</item>
   <item name="android:windowNoTitle">true</item>
   <item name="android:windowFullscreen">true</item>
   <item name="android:windowContentOverlay">@null</item>
   <item name="android:windowActionBar">true</item>
  </style>

Check your MainActivity Flags as shown below

enter image description here

Add SplshActivity class

  [Activity(Theme = "@style/MainTheme.Splash",
          MainLauncher = true,
          NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
    // Launches the startup task
    protected override void OnResume()
    {
        base.OnResume();
        StartActivity(new Intent(Application.Context, typeof(MainActivity)));
    }
}
0
Liyun Zhang - MSFT On

At first, if you want to hide the action bar in your activity, you need to change the <item name="android:windowActionBar">true</item> to <item name="android:windowActionBar">false</item>.

And then does the notification bar mean the system's status bar? If so you can try to use the following code to hide it:

WindowInsetsControllerCompat windowInsetsController =
  ViewCompat.getWindowInsetsController(WindowDecorView);
windowInsetsController.hide(WindowInsetsCompat.Type.statusBars());

For more infromation, you can check the official document about hiding the system bars.