Vai*_*yal 93 android android-studio
我最近将目标 SDK 版本更改为 31 (Android 12),升级后我开始收到此警告:
应用程序不应提供自己的启动屏幕。
这是截图:
有没有更好的方法来创建启动画面?
注意: 我知道这只是一个警告,可以忽略,但我现在要求推荐创建启动屏幕的方法。
qki*_*qki 79
现在有更好的方法。对于 Android 12,有全新的 Splash Screen Api,它也适用于以前的版本,请在此处查看更多信息
它支持主题、自定义动画,并且使用起来超级简单。
Pie*_*rek 60
只需更改名称即可,不要在其中使用“splash”。
Aru*_*ani 11
从 Android 12 开始,SplashScreen API 为在 Android 12 或更高版本的设备上运行的所有应用启用新的应用启动动画。这包括启动时进入应用程序的动作、显示应用程序图标的启动屏幕以及到应用程序本身的过渡。
太长了;Android 提供了一个新的 API 来集成 SplashScreen。首先,删除 SplashScreen,然后按照下面的代码块操作。
添加构建gradle
implementation 'androidx.core:core-splashscreen:1.0.0-rc01'
请按照以下步骤操作。
定义:
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/ed_colorPrimary</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_logo</item>
<item name="windowSplashScreenAnimationDuration">200</item>
<!-- Set the theme of the Activity that directly follows your splash screen. -->
<!-- Required -->
<item name="postSplashScreenTheme">@style/Theme.MyAppTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后在清单中检查并验证您是否给出了Theme.App.Starting
<application
...
android:theme="@style/Theme.App.Starting" >
...
<activity
android:name=".ui.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTask"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
最后,别忘了补充一下。
class MainActivity : BaseActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val splashScreen = installSplashScreen()
...
Run Code Online (Sandbox Code Playgroud)
您还可以使用以下命令抑制它@SuppressLint("CustomSplashScreen"):
@SuppressLint("CustomSplashScreen")
public class SplashActivity extends AppCompatActivity {
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33365 次 |
| 最近记录: |