【问题标题】:Xamarin forms splash screen issueXamarin 表单启动画面问题
【发布时间】:2016-05-10 08:28:22
【问题描述】:

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

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

}

【问题讨论】:

  • 修复了将 NoHistory 标志设置为 false 时的问题。

标签: xamarin xamarin.forms xamarin.android splash-screen


【解决方案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();
    }
}

【讨论】:

  • 对应的文件应该存放在哪里? (什么标题?)
  • 我不确定你在做什么,但页面的标题是内容页面的属性。该文件可以存储在您喜欢的任何命名空间中。我通常会在初始屏幕上隐藏标题栏,使其无关紧要。
  • 内容页面通常存储在 Android/iOS/someotherpaltform 引用的 .NET Standard 项目中。 (旧 xamarin 项目中的 PCL/SAP)
【解决方案2】:

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

这是我们使用的“标准”启动活动,让 Xamarin.Android 负责计时等:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    相关资源
    最近更新 更多