简体   繁体   English

Xamarin 表单启动画面问题

[英]Xamarin forms splash screen issue

A black screen with app title is showing when minimizing the app while loading splash screen , also the first screen will display after some time.在加载启动画面时最小化应用程序时会显示带有应用程序标题的黑屏,一段时间后也会显示第一个屏幕。 Here is my splash activity and main activity classes.这是我的飞溅活动和主要活动课程。

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

}

You tagged Xamarin.Forms so it should be as simple as..你标记了 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();
    }
}

Not certain if the activity attribute ScreenOrientation = ScreenOrientation.Behind) is causing any issues, we don't use that in our apps.不确定活动属性ScreenOrientation = ScreenOrientation.Behind)是否导致任何问题,我们不会在我们的应用程序中使用它。

Here is a "standard" splash activity we do use, letting Xamarin.Android take care of timing etc:这是我们确实使用的“标准”启动活动,让 Xamarin.Android 负责计时等:

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

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

You might try simplifying your app in similar fashion.您可以尝试以类似的方式简化您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM