Xamarin形成闪屏问题

时间:2016-05-10 08:28:23

标签: xamarin xamarin.android xamarin.forms

在加载启动画面时最小化应用程序时会显示带有应用程序标题的黑屏,也会在一段时间后显示第一个屏幕。这是我的启动活动和主要活动类。

[Activity(Theme = "@style/Theme.Splash", Icon = "@drawable/icon", MainLauncher = true, NoHistory = true,
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
    ScreenOrientation = ScreenOrientation.Behind)]
public class SplashActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        var dpWidth = Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density;


        RequestedOrientation = dpWidth > 700 ? ScreenOrientation.Unspecified : ScreenOrientation.Portrait;

        ThreadPool.QueueUserWorkItem(o => LoadActivity());
    }

    private void LoadActivity()
    {

        RunOnUiThread(() => StartActivity(typeof(MainActivity)));
    }


    public override void OnBackPressed()
    {
        Environment.Exit(0);
    }
} 



[Activity(Label = "HACCP", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsApplicationActivity
{


    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        ActionBar.SetIcon(Android.Resource.Color.Transparent);

        Forms.Init(this, bundle);

        // some function //

        LoadApplication(new App());
    }

}

2 个答案:

答案 0 :(得分:1)

你标记了Xamarin.Forms所以它应该像..

一样简单
class App : Application
{
    public App()
    {
        MainPage = new MySplashPage();
    }
}

class MySplashPage : ContentPage
{
    public MySplashPage()
    {
        Task.Delay(3000); //show my pretty splash for 3 seconds
        Application.Current.MainPage = new MyOtherSpiffyPage();
    }
}

答案 1 :(得分:0)

不确定活动属性ScreenOrientation = ScreenOrientation.Behind)是否导致任何问题,我们不会在我们的应用中使用它。

这是一个"标准"我们使用的飞溅活动,让Xamarin.Android处理时间等问题:

public class SplashActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Start main.
        StartActivity(typeof(MainActivity));
    }
}

您可以尝试以类似的方式简化您的应用。