c# - Xamarin 在启动画面后形成 10 秒黑屏
问题描述
一开始我应该说我已经阅读了所有类似的问题,但它们无法解决我的问题。
我的 Xamarin Forms 项目中有一个启动画面,并检查其中的凭据,然后在每个条件下启动 Main Activity,并针对条件使用不同的参数。当启动画面完成它的工作并消失时,应用程序显示黑屏大约 10 秒,然后显示主页
这是我的飞溅:
[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);
}
这是我的 MainActivity :
[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 中进行测试
推荐阅读
- java - ConcurrentHashMap 的 Kotlin 并发
- python - 主模块外的 Python 多处理:计算速度慢
- python - pandas-datareader 世界银行 API 损坏
- html - setTimeout 在此时钟项目中不起作用
- laravel - Laravel websocket 的网址是什么?
- c# - 教程视频是 2018 年制作的,需要帮助。应该是开关
- reactjs - 如何从我编写的自定义表单的子组件修改父组件的状态。这也可能影响父母的其他孩子
- logging - 在 Sublime Text 3 中默认/启动时记录命令?
- java - 在 JAVA 中的 JSON 反序列化期间更改两个文件名
- node.js - 在 yarn install 上编译 node-sass 时出错