react-native-splash-screen "react-native-splash-screen": "^3.0.1" 使用概要

未结帖
0 676
ajian admin_jim 2018-02-18
悬赏:5飞吻

步骤一:npm i react-native-splash-screen@3.0.1 --save

       react-native link react-native-splash-screen


步骤二:



Android:

更新你的 MainActivity.java 文件如下:

public class MainActivity extends ReactActivity {   @Override
    protected void onCreate(Bundle savedInstanceState) {        SplashScreen.show(this);  // 添加这一句
        super.onCreate(savedInstanceState);
    }    // ...other code}

iOS:

更新你的AppDelegate.m 文件如下:

#import "AppDelegate.h"
#import "RCTRootView.h"
#import "SplashScreen.h"  // here
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    // ...other code

    [SplashScreen show];  // 添加这一句,这一句一定要在最后
    return YES;
}@end


步骤三:
Android:
创建一个名为 launch_screen.xml 的布局文件放在android\app\src\main\res\layout来自定义你的启动屏幕。
然后把引导图 launch_screen.jpg 放在 android\app\src\main\res\drawable  文件夹下
<?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>

然后启用app主题透明选项来解决在APP启动时因主题原因导致的短暂白屏的问题,具体步骤如下:
打开 android/app/src/main/res/values/styles.xml文件,添加 <item name="android:windowIsTranslucent">true</item>,如下 :
<resources>   
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">        
        <!-- Customize your theme here. -->
        <!--设置透明背景-->
        <item name="android:windowIsTranslucent">true</item>
    </style>
</resources>

如果你只做了以上步骤,你的程序会闪屏后退出,所以你需要在android\app\src\main\res\values\colors.xml文件中
写如下代码

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary_dark">#660B0B0B</color>
</resources>

做了以上步骤android启动屏就完成了

更详细的介绍,可以查看 examples https://github.com/crazycodeboy/react-native-splash-screen/tree/master/examples
iOS
iOS可以通过LaunchImage或LaunchScreen.xib来自定义你的启动屏幕。
更详细的介绍,可以查看 examples




热忱回答0


最近热帖

近期热议

  1. javascript——prototype与__proto 9
  2. Mysql 中出现的Data truncated for column 3
  3. 在nginx中使用x-sendfile的解决方案 3
  4. 高版本jQuery面插件实现Ajax上传图片 1
  5. Thinkphp Socket.class.php 类的使用 1
  6. 使用ionic3创建第一个App 0
  7. ios-oc html5 0
  8. nginx.conf 0
  9. 基于ionic3.4.0的项目搭建 0
  10. php 缩略图 0