【发布时间】:2021-02-25 11:21:00
【问题描述】:
我在我的应用程序中添加了一个启动画面,它可以正常工作。
但是当我在互联网上搜索时,所有关于 android 启动画面的指南和操作说明都不同。
现在我想知道我的解决方案是否有缺点?
我没有额外的启动活动,我的解决方案是为我的主要活动设置背景,一旦加载,应用程序就会显示在背景上。这显着减少了添加启动屏幕的代码。
注意:
我得到了在启动画面和应用程序启动之间显示的白屏的解决方案,但这不是我问题的重点。
这里是 android splash 的重要文件。
Android 样式.xml
<resources>
<style name="AppTheme" parent="@style/Theme.MaterialComponents.Light.NoActionBar">
<item name="colorOnActionBar">?attr/colorOnSurface</item>
<item name="android:windowBackground">@drawable/splash_background</item>
<!-- These are the React default theme colors, if your theme is different, adjust accordingly -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorSecondary">@color/colorSecondary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
AndroidManifest.xml
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
【问题讨论】:
-
您想知道这是一种好的解决方法还是您必须创建活动?
-
是的,如果我的解决方案有一些负面影响或者是不好的做法,我想得到一些反馈。就流程而言,我的解决方案可以正常工作并显示启动画面。
-
如果它适合你然后使用它,但它不是很灵活,因为你似乎替换了整个应用程序的默认背景。您可以只替换主要活动的背景,但如果您只有一个活动,则没关系。
-
只有一个建议,因为您已标记 react-native ,如果您想为 android 和 iOS 设备添加启动画面,请添加类似 SpashScreen.js 的内容并将其放入导航器的初始路由选项, android 启动画面仅适用于 android 设备。
标签: android react-native splash-screen