react-native-splash-screen 在android启动屏使用
环境
1 | XCode Version 10.2 (10E125) |
安装
1 | yarn add react-native-splash-screen |
使用
1 | import SplashScreen from 'react-native-splash-screen' |
配置
导入启动屏资源
引用启动屏资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14./android/app/src/main/res/layout
mkdir launch_screen.xml
-----
android:background="@mipmap/launch_screen" 为启动屏资源
代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/launch_screen"
android:orientation="vertical">
</LinearLayout>
-----在启动APP时使用 onCreate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20/android/app/src/main/java/com/{你的项目名}/MainActivity.java
新增
------
import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
...
}
----