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.