加载后启动画面 dispose/remove
Splash screen dispose/remove after loaded
我在我的 xamarin android 应用程序中启动启动画面,但启动画面不断出现
在其他页面上作为背景。
无论我做什么,它都在那里。
我已经尝试 "Finish" activity,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 中的主题:
[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);
}
}
替代创建新主题的另一种解决方案是在每个 activity 不是 SplashScreen activity 的父视图的布局文件中设置背景颜色 activity。
您的问题主要是因为两个活动使用了相同的主题。
在“MainActivity”中将主题从“@style/MyTheme.Splash”更改为“@style/MainTheme”,这将使主要 activity 使用默认主题。
我在我的 xamarin android 应用程序中启动启动画面,但启动画面不断出现 在其他页面上作为背景。
无论我做什么,它都在那里。
我已经尝试 "Finish" activity,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 中的主题:
[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);
}
}
替代创建新主题的另一种解决方案是在每个 activity 不是 SplashScreen activity 的父视图的布局文件中设置背景颜色 activity。
您的问题主要是因为两个活动使用了相同的主题。
在“MainActivity”中将主题从“@style/MyTheme.Splash”更改为“@style/MainTheme”,这将使主要 activity 使用默认主题。