Xamarin 在启动画面后形成 10 秒黑屏
Xamarin Forms 10 seconds black screen after Splash Screen
起初我应该说我已经阅读了所有类似的问题,他们不能解决我的问题。
我的 Xamarin Forms 项目中有一个启动画面,并检查其中的凭据,然后在每个条件下启动 Main Activity,并针对条件使用不同的参数。当启动画面完成工作并消失时,应用程序显示黑屏约 10 秒,然后显示主页面
这是我的 Splash :
[Activity(Theme = "@style/MainTheme.Splash",
MainLauncher = true,
NoHistory = true,
ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashActivity : Activity
{
static readonly string TAG = "X:" + typeof(SplashActivity).Name;
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Log.Debug(TAG, "SplashActivity.OnCreate");
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
async void SimulateStartup()
{
Some Code ...
InvokeMainActivity("SomeType");
}
private void InvokeMainActivity(string type)
{
Intent _activity = new Intent(Application.Context, typeof(MainActivity));
_activity.PutExtra("Key", type);
_activity.AddFlags(ActivityFlags.NoAnimation);
StartActivity(_activity);
}
这是我的主Activity :
[Activity(Label = "@string/app_name",
Icon = "@drawable/icon",
Theme = "@style/MainTheme",
MainLauncher = false,
LaunchMode = LaunchMode.SingleTask,
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.Locale | ConfigChanges.LayoutDirection)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override async void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
Rg.Plugins.Popup.Popup.Init(this, bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);
Window.DecorView.LayoutDirection = LayoutDirection.Rtl;
string type = Intent.GetStringExtra("SomeType");
LoadApplication(new App(type));
}
}
我该如何解决这个问题?
感谢@LeonLu-MSFT,我在 style.xml 中添加了此代码,而 MainActivity 和 Spalsh Screen
没有任何变化
<item name="android:windowIsTranslucent">true</item>
我没有 Mac 和 ios 设备来测试 ios
我也遇到了类似的问题。我通过添加
修复了它
<item name="android:windowIsTranslucent">true</item>
在~\Resources\values\styles.xml.
因此,如果您遇到类似的问题,请按照下面的屏幕截图添加它,希望它也对您有用:
起初我应该说我已经阅读了所有类似的问题,他们不能解决我的问题。
我的 Xamarin Forms 项目中有一个启动画面,并检查其中的凭据,然后在每个条件下启动 Main Activity,并针对条件使用不同的参数。当启动画面完成工作并消失时,应用程序显示黑屏约 10 秒,然后显示主页面
这是我的 Splash :
[Activity(Theme = "@style/MainTheme.Splash",
MainLauncher = true,
NoHistory = true,
ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashActivity : Activity
{
static readonly string TAG = "X:" + typeof(SplashActivity).Name;
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Log.Debug(TAG, "SplashActivity.OnCreate");
}
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
async void SimulateStartup()
{
Some Code ...
InvokeMainActivity("SomeType");
}
private void InvokeMainActivity(string type)
{
Intent _activity = new Intent(Application.Context, typeof(MainActivity));
_activity.PutExtra("Key", type);
_activity.AddFlags(ActivityFlags.NoAnimation);
StartActivity(_activity);
}
这是我的主Activity :
[Activity(Label = "@string/app_name",
Icon = "@drawable/icon",
Theme = "@style/MainTheme",
MainLauncher = false,
LaunchMode = LaunchMode.SingleTask,
ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.Locale | ConfigChanges.LayoutDirection)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override async void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
Xamarin.Essentials.Platform.Init(this, bundle);
Rg.Plugins.Popup.Popup.Init(this, bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);
Window.DecorView.LayoutDirection = LayoutDirection.Rtl;
string type = Intent.GetStringExtra("SomeType");
LoadApplication(new App(type));
}
}
我该如何解决这个问题?
感谢@LeonLu-MSFT,我在 style.xml 中添加了此代码,而 MainActivity 和 Spalsh Screen
没有任何变化<item name="android:windowIsTranslucent">true</item>
我没有 Mac 和 ios 设备来测试 ios
我也遇到了类似的问题。我通过添加
修复了它<item name="android:windowIsTranslucent">true</item>
在~\Resources\values\styles.xml.
因此,如果您遇到类似的问题,请按照下面的屏幕截图添加它,希望它也对您有用: