react-native-splash-screen 使用- android

楚硕
2023-12-01

1:安装

yarn add react-native-splash-screen

react-native link react-native-splash-screen

2:android配置

MainActivity.java中添加
import org.devio.rn.splashscreen.SplashScreen;
import android.os.Bundle;


public class MainActivity extends ReactActivity {

    @Override    
    protected void onCreate(Bundle savedInstanceState) {
         SplashScreen.show(this);  // here
         super.onCreate(savedInstanceState);
    }
}

res/layout中添加文件:launch_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical" android:layout_width="match_parent"
                android:layout_height="match_parent">
    <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/launch_screen" android:scaleType="centerCrop" />
</RelativeLayout>

res/drawable-xxxhdpi中添加启动页素材:launch_screen.png

res/values/styles.xml中添加

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!--设置透明背景-->
        <item name="android:windowIsTranslucent">true</item>
    </style>

</resources>

3:React-Native中调用

//引入头文件
import SplashScreen from "react-native-splash-screen";

//关闭启动页
SplashScreen.hide();

 

 类似资料: