加载后启动画面处理/删除 [英] Splash screen dispose/remove after loaded
问题描述
我正在我的 xamarin android 应用程序中启动启动画面,但会发生启动画面不断出现的情况在其他页面作为背景.
I am launching a splash screen in my xamarin android application and what happens is the splash screen keeps appearing on other pages as background.
无论我做什么,它都在那里.
Whatever I do it's there.
我试图完成"活动,NoHistory=true 但什么都没有,继续在后台的其他页面上显示.
I have tried to "Finish" the activity,NoHistory=true but nothing ,keeps showing on other pages in the background.
取自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"
引起的.两个活动使用相同的主题.
This is caused by Theme = "@style/MyTheme.Splash"
. Both activities use the same theme.
为其他活动创建不同的主题.
Create a different theme for the other activities.
<style name="MyTheme.Main" parent ="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<小时>
在活动中更改主题:
Change the theme in Activity:
[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);
}
}
这篇关于加载后启动画面处理/删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!