我正在xamarin android应用程序中启动启动画面,发生的是启动画面不断出现
在其他页面上作为背景。

无论我做什么,都在那里。

我试图“完成”事件,NoHistory = true,但是什么也没有完成,使后台的其他页面无法显示。

取自
https://alexdunn.org/2017/02/07/creating-a-splash-page-for-xamarin-forms-android/

有什么想法吗?

      [Activity(Label = "MyApp",
    Theme = "@style/MyTheme.Splash",
    Icon = "@drawable/icon",
    MainLauncher = true,
    NoHistory = true,
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            TabLayoutResource = Resource.Layout.tabs;
            ToolbarResource = Resource.Layout.toolbar;

            base.OnCreate(bundle);

            Xamarin.Forms.Forms.Init(this, bundle);
            LoadApplication(new App(new AndroidInitializer()));

        }
    }


     [Activity(
            Theme = "@style/MyTheme.Splash",
            MainLauncher = true,
            NoHistory = true,
            ScreenOrientation = ScreenOrientation.Portrait)]
        public class SplashActivity : AppCompatActivity
        {

            public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
            {
                base.OnCreate(savedInstanceState, persistentState);

            }


          protected override void OnResume()
         {
           base.OnResume();
             var startUp = new Task(() =>
            {
             var intent = new Intent(this, typeof(MainActivity));
            StartActivity(intent);
        });
    startUp.ContinueWith(t => Finish());

    startUp.Start();
    }

      <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light">
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
      </style>

最佳答案

这是由Theme = "@style/MyTheme.Splash"引起的。两种事件都使用相同的主题。

为其他事件创建一个不同的主题。

<style name="MyTheme.Main" parent ="Theme.AppCompat.Light">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

在事件中更改主题:
[Activity(
    Theme = "@style/MyTheme.Main",
    MainLauncher = true,
    NoHistory = true,
    ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashActivity : AppCompatActivity
{

    public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
    {
        base.OnCreate(savedInstanceState, persistentState);

    }
}

关于xamarin - 初始屏幕在加载后进行处理/删除,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47180471/

10-12 12:36
查看更多