can I change the splash screen when run it?

mc 3,701 Reputation points
2024-04-11T11:15:15.4+00:00

in android MAUI

when I run the APP and will get data from server and I will get one image how to set the image to splash screen then I next open the APP it can show in the slpash screen?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,895 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,656 Reputation points Microsoft Vendor
    2024-04-15T07:21:24.7+00:00

    Hello,

    Firstly, please open your project's csproj file, you can double click your project in VS, then csproj file will be opened. Remove <MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" /> line.

    Then, create xml file called styles.xml in Platforms/Android/Resources/values folder and set the build action to AndroidResource manually.

    Copy following style(hide the android native splash screen and the native navigationbar) code in styles.xml.

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
    
    
       <style name="MainTheme" parent="Theme.MaterialComponents.DayNight">
    
    
           <item name="android:windowIsTranslucent">true</item>
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="windowActionModeOverlay">true</item>
        </style>
    </resources>
    

    Next, open your MainActivity.cs change the **Theme ** value to MainTheme.

      
    [Activity(Theme = "@style/MainTheme", MainLauncher = true, ...)]
    

    Then you can create a ContentPage called SplashPage and add controls that you want to show. change the MainPage in the App.xaml.cs

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

    In the end, Add code about changing MainPage in OnAppearing method of SplashPage.

    public partial class SplashPage : ContentPage
    {
        public SplashPage()
        {
            InitializeComponent();
    
    
       }
        protected override async void OnAppearing()
        {
            base.OnAppearing();
    
    
           await  Task.Delay(2000).ContinueWith(t => {
              MainThread.InvokeOnMainThreadAsync(() => {
    
    // I change the MainPage to AppShell, you can change whatever page that you want.
                  Application.Current.MainPage=new AppShell();
              });
    
    
           });
    
    
       }
    }
    

    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