我正在尝试确定创建应用启动画面的最佳方法,同时考虑 Google 关于尽可能选择单个 Activity 应用的最新建议。
看这里:
"The new approach is to use one-activity structure whenever possible."
这里:
我发现的任何好的闪屏方法都有一个专门用于闪屏的 Activity:
有没有其他人有过在单个 Activity 应用程序中创建启动画面的经验?单个 Activity 推荐是否包括闪屏或它是一种特殊情况?有没有人对此有任何好的例子或建议?
干杯, 保罗。
最佳答案
我使用的方法如下:
首先为背景定义一个drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/green"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
2。定义一个新样式以在 splashScreen 中使用:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
3。让您的 Activity 工具使用启动主题:
<activity
android:name=".MainActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
4.在创建时,在 super 调用之前和设置内容 View 之前设置默认应用主题:
override fun onCreate(savedInstanceState: Bundle) {
setTheme(android.R.style.AppTheme)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
}
这种方法是我在多个 Activity 中一直使用的方法,因为它遵循 google 制定的指南:它会立即显示启动画面并且不会停留超过需要的时间。
关于android - 单个 Activity 应用程序中的启动画面方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52835697/