android 集成react native splash screen
rn版本 0.55.4
这个版本试了多次发现对应react native splash screen为3.0.9的最好
yarn add react native splash screen@3.0.9
然后react-native link react-native-splash-screen
然后
就是在MainActivity.java添加一些配置
import android.os.Bundle; // here import com.facebook.react.ReactActivity; // react-native-splash-screen >= 0.3.1 import org.devio.rn.splashscreen.SplashScreen; // here // react-native-splash-screen < 0.3.1 import com.cboy.rn.splashscreen.SplashScreen; // here public class MainActivity extends ReactActivity { @Override protected void onCreate(Bundle savedInstanceState) { SplashScreen.show(this); // here super.onCreate(savedInstanceState); } // ...other code }
然后在app/src/main/res/layout加一个launch_screen.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/launch_screen"> </LinearLayout>
不加这个,直接run android 会build success但是导致app崩溃