我正在使用来自https://github.com/zoontek/react-native-bootsplash的这个库https://github.com/zoontek/react-native-bootsplash,我完成了以下步骤:
我编辑了android/build.gradle文件:
buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 23 // <- AndroidX splashscreen has basic support for 21 (only the background color), so 23 is best
compileSdkVersion = 31 // <- set at least 31
targetSdkVersion = 31 // <- set at least 31然后编辑你的android/app/build.gradle文件:
dependencies {
// …
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation "androidx.core:core-splashscreen:1.0.0" // Add this line
// …编辑您的android/app/src/main/res/values/styles.xml文件:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Your base theme customization -->
</style>
<!-- BootTheme should inherit from Theme.SplashScreen -->
<style name="BootTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/bootsplash_background</item>
<item name="windowSplashScreenAnimatedIcon">@mipmap/bootsplash_logo</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
</resources>编辑您的android/app/src/main/AndroidManifest.xml文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rnbootsplashexample">
<!-- … -->
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/BootTheme"> <!-- Replace @style/AppTheme with @style/BootTheme -->
<!-- … -->
</application>
</manifest>最后编辑您的android/app/src/main/java/com/yourprojectname/MainActivity.java文件:
// …
// Add these required imports:
import android.os.Bundle;
import com.zoontek.rnbootsplash.RNBootSplash;
public class MainActivity extends ReactActivity {
// …
@Override
protected void onCreate(Bundle savedInstanceState) {
RNBootSplash.init(this); // <- initialize the splash screen
super.onCreate(savedInstanceState); // or super.onCreate(null) with react-native-screens
}
}但是它没有在启动屏幕上显示图标。
发布于 2022-08-20 09:07:38
使用yarn react-native generate-bootsplash <logoPath>
之前,应该使用cd android && ./gradlew clean && cd ..生成编译文件夹。
https://stackoverflow.com/questions/73421574
复制相似问题