A splash screen is a graphical control element consisting of a window containing an image, a logo, and the current version of the software. A splash screen usually appears while a game or program is being launched.
Reading this article, you will learn how to add Splash Screen in Xamarin.Forms application for Android and Universal Windows Platform with XAML and Visual C#, using Visual Studio 2017 RC.
The following important tools are required for developing UWP,
- Windows 10 (Recommended).
- Visual Studio 2017 RC Community/Enterprise/Professional Edition (It is a Free trial software available online).
- Using Visual studio 2017 Installer, enable the feature of Mobile development with .NET.
Now, we can discuss step by step app development.
Step 1
Open Visual Studio 2017 RC. Go to Start -> New Project-> Select Cross-Platform (under Visual C#->Cross Platform App-> Give suitable name for your app (XamFormSplash) -> OK.
Step 2
Select the Cross Platform template as Blank App, Set UI Technology as Forms, and Sharing as PCL.
Step 3
Now, creating project “XamFormSplash_Droid” …
Step 4
Afterwards, Visual Studio creates 4 projects and displays Getting Started.XamarinPage
Step 5
For adding splash screen feature in XamFormSplash_Droid project, open MainActivity.cs and set the MainLauncher = false.
Add a new Activity file for Splash Screen demo, right click XamFormSplash_Droid project, and select Add-> NewItem.
Select ->Visual C#-> Activity-> Give the relevant activity name (Splash.cs).
Add the following code in Splash.cs for displaying splash screen image in Android project.
- [Activity(Theme = "@style/splashTheme", MainLauncher = true, NoHistory = true)]
- protected override void OnCreate(Bundle savedInstanceState) {
- base.OnCreate(savedInstanceState);
-
- StartActivity(typeof(MainActivity));
- }
Add the splash screen image in XamFormSplash_Droid project Resources-> Drawable folder, and add the splash screen style to the Styles.xml in XamFormSplash_Droid project values folder.
- <style name="splashTheme" parent="android:Theme">
- <item name="android:windowBackground">@drawable/xamarin_logo</item><item name="android:windowNoTitle">true</item>
- </style>
Step 6
For adding splash screen feature in XamFormSplash_UWP project, open Package.Appmanifest in XamFormSplash_UWP project -> select Visual Assets -> set the Source Splash screen image in Asset Generator, and click the "Generate" button.
Step 7
Change the "Configuration Manager" settings. Go to Build -> Configuration Manager, and uncheck the "Build" and "Deploy" options to the iOS and check the "Droid" and "UWP".
Step 8
Deploy your app in Local Machine. The output of the XamFormSplash app is given below.
After showing the splash screen.
Summary
Now, you have successfully tested Splash Screen in Xamarin.Forms application, using Visual C# and Xamarin in Visual Studio 2017 RC.