Unable to make full screen splash in .NET MAUI

Md Mosabbir Alam 20 Reputation points
2024-06-11T04:27:11.4933333+00:00

How can I make splash to display in full screen instead of just at the center of the mobile screen in .NET MAUI? I've tried different base sizes, but not working. Target android version up-to 13.

<ItemGroup>
<MauiSplashScreen Include="Resources\Splash\splash.svg" />
</ItemGroup>
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,596 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
814 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 76,551 Reputation points Microsoft Vendor
    2024-06-11T08:02:10.25+00:00

    Hello,

    I've tried different base sizes, but not working. Target android version up-to 13

    On Android 12, it's not possible to make image to full screen in splash screen. It is only possible to customize it: icon, window background, exit animation. Please see this google document: Splash screen

    However, here is workaround to make the splash screen to transparent, then you can create a splashScreen with Contentpage, add images in the contentpage.

    Step 1. Create styles.xml at Platforms/Android/Resources/values folder, and add the following code to customize style. And make sure the build action of styles.xml is AndroidResource.

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
    <style name="MyTheme.Splash" parent ="MainTheme">
    <item name="android:windowIsTranslucent">true</item>			      
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowSplashScreenAnimatedIcon">@android:color/transparent</item>
    <item name="android:windowSplashScreenAnimationDuration">0</item>
    </style>
    </resources>
    

    Step2. Open your MainActivity.cs, change the theme to Theme = "@style/MyTheme.Splash".

    [Activity(Theme = "@style/MyTheme.Splash", ...)]
    public class MainActivity : MauiAppCompatActivity
    {
    }
    

    Step3, please create a Contentpage called SplashScreen add your image to it. And open the Mainpage after several seconds by Task.Delay() and Application.Current.MainPage = new MainPage (); like following code.

    protected override async void OnAppearing()
    {
        base.OnAppearing();
     
       await Task.Delay(1000).ContinueWith(t => {
           MainThread.InvokeOnMainThreadAsync(() => {
               Application.Current.MainPage = new MainPage ();
           });
        }); 
    }
    

    Step4 open the App.xaml.cs, change the MainPage to the SplashScreen.

    public partial class App : Application
      {
          public App()
          {
              InitializeComponent();
     
              MainPage = new SplashScreen();
          }
      }
    

    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.


0 additional answers

Sort by: Most helpful

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.