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

Time:10-04

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

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)));
    }
}

CodePudding user response:

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.

  • Related