android - 启动画面在每个页面上显示为背景
问题描述
我的初始屏幕在开始时显示,但随后它继续运行,就好像它是页面的背景一样。我必须使用 BackgroundColor 以使背景不可见,但任何过渡都非常简短地显示背景。
这是我的 MainActivity.cs
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace apptest.Droid
{
[Activity(Label = "apptest", Icon = "@drawable/appmain", Theme = "@style/MyTheme.Splash", NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}
这是我的 SplashActivity.cs
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Support.V7.App;
using Android.Util;
namespace apptest.Droid
{
[Activity(Theme = "@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : AppCompatActivity
{
static readonly string TAG = "X:" + typeof (SplashActivity).Name;
public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
base.OnCreate(savedInstanceState, persistentState);
Log.Debug(TAG, "SplashActivity.OnCreate");
}
// Launches the startup task
protected override void OnResume()
{
base.OnResume();
Task startupWork = new Task(() => { SimulateStartup(); });
startupWork.Start();
}
// Prevent the back button from canceling the startup process
public override void OnBackPressed() { }
// Simulates background work that happens behind the splash screen
async void SimulateStartup ()
{
Log.Debug(TAG, "Performing some startup work that takes a bit of time.");
await Task.Delay(8000); // Simulate a bit of startup work.
Log.Debug(TAG, "Startup work is finished - starting MainActivity.");
StartActivity(new Intent(Application.Context, typeof (MainActivity)));
}
}
}
有没有办法让闪屏消失?
谢谢,麻烦您了!:)
解决方案
正如大卫所说,不要为 MainActivity 设置 Splash 主题。您可以使用项目创建的默认主题。
[Activity(Label = "SplashScreen", Icon = "@mipmap/icon", Theme = "@style/MainTheme", NoHistory = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
截屏:
您可以从 Github 下载源文件以供参考。 https://github.com/WendyZang/Test/tree/master/SplashScreen
推荐阅读
- python-3.x - 有没有办法调整 tkinter 按钮的大小?
- python - 使用另一个列表 python 从列表创建索引值数组
- java - 为什么Java会在这种情况下将double类型转换为float类型?
- oracle - Oracle 数据库是否有未解决的问题列表?
- node.js - 将 NextJs 托管到 IIS
- python - 'bool' 对象没有属性 'rect'
- ajax - 如果循环的内容发生了变化,是否可以自动更新 Wordpress 循环?
- c - 仅在 ISR 中读取的变量的易失性?
- java - 触发 REST 调用时,部分汉字无法解释
- c# - 我的模拟 HttpRequestMessage 中缺少什么导致 CreateResponse 中的 ArgumentNullException?