首先显示启动屏幕,然后淡出为黑色,然后显示该屏幕...
最后,它导航到应用程序的主屏幕。
这不令人满意。
如何摆脱黑色和上面的空白屏幕?
我的代码如下:
- 启动画面活动
[Activity(Label = "App", MainLauncher = true, NoHistory = true, Theme = "@style/Splash",
ConfigurationChanges = ConfigChanges.ScreenSize)]
public class SplashActivity : Activity
{
protected override void OnResume()
{
base.OnResume();
var startupWork = new Task(() =>
StartActivity(new Intent(Application.Context, typeof(MainActivity))));
startupWork.Start();
}
}
- styles.xml:
<style name="Splash" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/splash</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
- splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="@color/SplashBackground" />
</item>
<item>
<bitmap
android:src="@drawable/icon"
android:tileMode="disabled"
android:gravity="center" />
</item>
</layer-list>
答案 0 :(得分:1)
您可以执行3个步骤:
[Activity(Label = "ApplicationName", Theme = "@style/Theme.Splash", MainLauncher =true, NoHistory =true ),] public class MySplashScreen : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here StartActivity(typeof(MainActivity)); } }
答案 1 :(得分:0)
“将我的评论转换为答案...”
将包含windowBackground
的主题应用于MainActivity
,并且不要使用单独的“闪屏”活动,因为您对该活动不做任何事情
<style name="Theme.ASushiApp.Main" parent="Theme.ASushiApp.Base">
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:windowBackground">@drawable/splash_screen_layer</item>
</style>
在MainActvity
的布局中,将根ViewGroup的可见性设置为invisible。
或者您可以将背景设置为@android:color/transparent
,并添加不确定的ProgressBar
以显示旋转进度轮。
这里的目标是允许您在设置应用程序时继续显示主题背景图片。
然后在OnCreate
上执行UI线程上必须要做的最低工作,然后启动Task
:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
~~~
// setup toolbar/actionbar, FindViewById assignments, etc..
~~~
new Task(InitalSetup).Start();
}
在后台,完成其余的设置,最后,在UI /主线程中,隐藏进度指示器或将根容器ViewGroup设置为可见,并将背景(Window.SetBackgroundDrawableResource)设置为纯色以清除您在主题中使用的图像。
async void InitalSetup()
{
// running on a background thread...
// setup db, any adapters, listeners, AdView handlers, etc...
// everything but direct UI changes, do those at the end on the UI/Main thread
~~~
RunOnUiThread(() =>
{
// finish setup on the UI items that have to run on UI thread, ie: adapter assignments
recyclerView.SetAdapter(adapter);
rootViewGroupContainer.Visibility = ViewStates.Visible;
// Or
progressBar.Visibility = ViewStates.Gone;
Window.SetBackgroundDrawableResource(Android.Resource.Color.Black);
});