Reputation: 910
I am trying to create splash screen for my android application, as shown in this link http://developer.xamarin.com/guides/android/user_interface/creating_a_splash_screen/
Unfortunately this link just shows how to make a splash screen using a drawable. But what I need to do is to create a splash screen using a Layout so that I can easily customize how it looks and make it compatible with different screen sizes.
Thanks
Upvotes: 2
Views: 4408
Reputation: 481
What you can do is to create a Activity that represents your splash screen. Ex: SplashActivity
. Then when your SplashActivity is created you start a timer (Ex: System.Timers.Timer
) with 3 seconds duration. When those 3 seconds have passed you simply start the main activity for your app.
To prevent the user from navigating back to the splash activity, you simply add the NoHistory = true
property to the ActivityAttribute (just above the activity class decleration).
See example:
[Activity(MainLauncher = true, NoHistory = true, Label = "My splash app", Icon = "@drawable/icon")]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Splash);
Timer timer = new Timer();
timer.Interval = 3000; // 3 sec.
timer.AutoReset = false; // Do not reset the timer after it's elapsed
timer.Elapsed += (object sender, ElapsedEventArgs e) =>
{
StartActivity(typeof(MainActivity));
};
timer.Start();
}
};
[Activity (Label = "Main activity")]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
}
Upvotes: 9