Easily Add Splash Screen In Xamarin.Forms


Introduction – Asplash screen is an image or Splash Screen is a better way to promote your application and gives people a warm welcome at the start or page that shows up when you first load your app. When the application is initializing, Xamarin.Forms does not have any functionality to add a splash screen. You should do this with platform.

Screen: Splash Screen

 

Creating the Project

Open Visual Studio Community 2017 and click New Project. Select Visual C# >> Cross Platform template >> Blank App (Xamarin.Forms Portable).

Step 1. Go in Andorid project.


Create new class SplashScreen.cs

 

Step. 2 Add a some code in SplashScreen.cs .

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

namespace LetsCookApp.Droid
{
[Activity(Label = “App2”, MainLauncher = true, NoHistory = true, Theme = “@style/Theme.Splash”, ConfigurationChanges = ConfigChanges.ScreenSize)]

public class SplashScreen : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Simulate a long loading process on app startup.
StartActivity(typeof(MainActivity));
Finish();
}
}
}

Step 3. Go in Andorid project.

Edit in MainActivity.cs file

In App default MainLauncher = true, chamge to MainLauncher = false. Show in above screenshort.

Step 4 . Add a some code in Styles.xml file.

In Android project.

=> App2.Droid >> Resources >> values >> styles.xml

Figure 1:

 

Figure 2: In styles.xml file

 

Step 5 . Add some code in styles.xml above in screen.

<style name=”Theme.Splash” parent=”android:Theme”>
<item name=”android:windowBackground”>@drawable/icon</item>
<item name=”android:windowNoTitle”>true</item>
<item name=”android:windowIsTranslucent”>false</item>
<item name=”android:windowIsFloating”>false</item>
<item name=”android:backgroundDimEnabled”>true</item>
</style>


In above screen line number 2 ( @drawable / icon) in place of icone you can change and set

“your screen name” Ex :- splash.png

Step 6 . Create a splash screen image in the following sizes. 

MDPI is = 320x480px
XHDPI is 2 x MDPI = 640x960px
XXHDPI is 3 x MDPI = 960x1440px
XXXHDPI is 4 x MDPI = 1280x1920px

Hopefully this will help you to understand and we have successfully created a Xamarin.Forms splash screen.

 

Easily Add Splash Screen In Xamarin.Forms

Post navigation


Leave a Reply

Your email address will not be published. Required fields are marked *