如何解决在加载主页和启动屏幕之间,Xamarin.Android
我有一个Xamarin.Forms应用程序,具有适用于ios和android的启动屏幕。它可以完美地在ios上运行。但是我在android上有问题。问题是:启动屏幕启动,在加载我的主页和启动屏幕之间之后,出现白屏。
I did a sample project for this problem.
我为启动屏幕执行了以下步骤:
我将splash_screen.xml添加到了Android可绘制文件夹中
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
<padding android:left="25dp"
android:right="25dp"
android:top="0dp"
android:bottom="0dp" />
<!-- Android -> Resources-> values -> colors.xml içerisinde tanımlı bu renk -->
</shape>
</item>
<item>
<bitmap
android:src="@mipmap/icon"
android:tileMode="disabled"
android:gravity="center" />
</item>
</layer-list>
我将初始屏幕样式添加到styles.xml
<style name="splashscreen" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBar">true</item>
</style>
我在MainActivity上将MainLauncher值设置为false。
[Activity(Label = "SplahScreenSample",Icon = "@mipmap/icon",LaunchMode = LaunchMode.SingleInstance,Theme = "@style/MainTheme",MainLauncher = false,ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
//...
}
我在Android项目中添加了SplashActivity :(它的主启动器值为true)
[Activity(Label = "SplahScreenSample",Theme = "@style/splashscreen",MainLauncher = true,NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
public override void OnCreate(Bundle savedInstanceState,PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState,persistentState);
}
protected override void OnResume()
{
base.OnResume();
StartActivity(new Intent(Application.Context,typeof(MainActivity)));
}
}
我的问题在哪里? 预先谢谢你。
注意: 其实我了解问题。问题是:MainTheme没有启动屏幕,但是MainActivity Theme是MainTheme。但我不知道该如何解决。 我试图将启动画面添加到MainTheme或尝试将MainActivity主题设置为启动画面。但是这些没有用。
解决方法
最佳方法在以下链接中起作用:https://xamarinhelp.com/creating-splash-screen-xamarin-forms/
因此,我将MainActivity主题设置为初始屏幕(主题=“ @ style / splashscreen”)。然后我以这种方式在MainActivity OnCreate方法中更改了主题:
protected override void OnCreate(Bundle bundle)
{
base.Window.RequestFeature(WindowFeatures.ActionBar);
// Name of the MainActivity theme you had there before.
// Or you can use global::Android.Resource.Style.ThemeHoloLight
base.SetTheme(Resource.Style.MainTheme);
base.OnCreate(bundle);
...
}
这行得通。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。