Splash screen is an image that appears while an application is loading. Splash Screens are typically used to notify the user that program is in the process of loading. In this Article, We will learn How to create Splash Screen for Android Application in Xamarin / Mono for Android. In my previous Article, We saw How to create Hello World Application in Xamarin. Before starting, I suggest you to read my previous Article.
Let's Begin:
1) Add two images(icon.png for icon and splash.png for displaying image on Splash Screen) in Resources\Drawable folder.
In above Code, We have created a Theme named as Theme.Splash and Set the Window Background as splash.png image present in Drawable folder. We have also disabled title bar by Setting windowNoTitle to true.
4) Add new Activity. Right Click on Project -> Go to Add -> New Item.
Select Activity and Give it a name SplashScreen.cs
In Activity1.cs, We have added a Button with Id="btn_Hello" from ToolBox and Added Click Event and Display Toast message on Clicking the Button.
Activity1.cs Code:
Build and Run the Application.
Final Preview:
I hope you like it. Thanks.
Let's Begin:
1) Add two images(icon.png for icon and splash.png for displaying image on Splash Screen) in Resources\Drawable folder.
2) Right Click on Values folder present in Resources folder of project -> Add -> New item.
3) Select XML File and give it a Name Styles.xml. In Android Application, We can assign themes to an Activity.
Styles.xml Code:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
|
4) Add new Activity. Right Click on Project -> Go to Add -> New Item.
Select Activity and Give it a name SplashScreen.cs
SplashScreen.cs Code:
using Android.App;
using Android.OS;
using System.Threading;
namespace Splash_Screen
{
//Set MainLauncher = true makes this Activity Shown
First on Running this Application
//Theme property set the Custom Theme for this Activity
//No History= true removes the Activity from BackStack
when user navigates away from the Activity
[Activity(Label="Splash Screen App",MainLauncher=true,Theme="@style/Theme.Splash",NoHistory=true,Icon="@drawable/icon")]
public class SplashScreen : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//Display Splash Screen for 4 Sec
Thread.Sleep(4000);
//Start Activity1 Activity
StartActivity(typeof(Activity1));
}
}
}
|
Activity1.cs Code:
using System;
using Android.App;
using Android.OS;
using Android.Widget;
namespace Splash_Screen
{
[Activity(Label = "Hello World App")]
public class Activity1 : Activity
{
Button btn_Hello;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//SetContentView
SetContentView(Resource.Layout.Main);
//Get btn_Hello Button control from the Manin.axml
Layout.
btn_Hello = FindViewById<Button>(Resource.Id.btn_Hello);
//Creating Click event of btn_Hello
btn_Hello.Click += btn_Hello_Click;
}
//btn_Hello Click Event
void btn_Hello_Click(object sender, EventArgs e)
{
//Display a Toast Message on Clicking the btn_Hello
Toast.MakeText(this,"Hello World App by Anoop",ToastLength.Short).Show();
}
}
}
|
Final Preview:
I hope you like it. Thanks.
[Download Source Code via Google Drive]
Watch Video:
Thanks Mr Anoop Kumar Sharma
ReplyDeleteHi Please Help me I'm Newbie on this Dev. I follow the whole instructions but I got this error. Severity Code Description Project File Line Suppression State
ReplyDeleteError CS0103 The name 'Resouce' does not exist in the current context Splash Screen Demo X:\Visual Studio\Projects\Splash Screen Demo\Splash Screen Demo\Activity1.cs 22 Active
Hi Harvy, I think you typed Resource incorrectly. Look at the error carefully:
DeleteThe name 'Resouce' does not exist in the current context Splash Screen Demo
Hi, Please help me. I follow the whole instructions but I got this error.
ReplyDeleteUnhandled Exception:
System.TypeLoadException: Could not load type 'App_Android.SplashActivity, App_Android, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' from assembly ''.
How can I solve it?
Check the blog about family locator software, to get all the information you need on the subject
ReplyDeletewhen i run the app its shows the error
ReplyDeleteunsupported major.minor version 52.0
i have visual studio 2015