我在我的xamarin android应用程序中启动了一个启动屏幕,所发生的情况是,splash屏幕一直作为背景出现在其他页面上。
不管我做什么它都在那里。
我一直试图“完成”活动,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>发布于 2017-11-08 13:14:22
这是由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);
}
}发布于 2017-11-08 15:06:18
另一种解决方案不是创建一个新的主题,而是在布局文件中为每个不是SplashScreen活动的活动中的父视图设置背景色。
发布于 2022-02-28 07:31:32
你的问题主要是由两个使用相同主题的活动引起的。
在"MainActivity“中,将主题从"@style/MyTheme.Splash”更改为"@style/MainTheme",这将使主活动使用默认主题。
https://stackoverflow.com/questions/47180471
复制相似问题