Xamarin : Splash screen using a Layout

北战南征 提交于 2019-12-11 02:43:17

问题


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


回答1:


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);
        }
    }


来源:https://stackoverflow.com/questions/27987195/xamarin-splash-screen-using-a-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!