2016-01-27 58 views
13

如何设置反应原生android的启动屏幕,我找不到任何关于该主题,我认为这很奇怪。如何设置启动屏幕的反应原生android

谢谢

+0

这里是你的问题的答案http://stackoverflow.com/a/39298315/277345 –

+1

[如何创建某种Splash屏幕/启动屏幕,在App加载后消失? (React Native)](http://stackoverflow.com/questions/33390013/how-to-create-some-kind-of-splash-screen-launching-screen-which-disappears-afte) –

回答

20

我曾试过3种以下方法。第一个是我目前用于android初始屏幕的反应原生项目。

  1. 使用由其他人写的npm包。

    参考:https://github.com/remobile/react-native-splashscreen

  2. 创建SplashScreen组分和之后重定向。

    参考:How to create some kind of Splash screen/Launching screen, which disappears after App loaded? (React Native)

  3. 本身在java代码。

    参考:https://www.bignerdranch.com/blog/splash-screens-the-right-way/

我具有在initialRoutecomponentDidMount()一个fetch请求。

使用上面列表中的第一种方式在显示启动画面时执行请求。

鉴于第二种方式,需要等到SplashScreen组件卸载。

第三种方法是编写和维护的代码略多。这里

+1

如何添加视频Android中的闪屏 – Lavaraju

1

本教程的伟大工程:

https://medium.com/react-native-development/change-splash-screen-in-react-native-android-app-74e6622d699

  1. 您需要创建在res /绘制闪屏。让我们把它splash_screen.xml

    <?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    
        <item 
         android:drawable="@android:color/white"/> 
    
        <item> 
         <bitmap 
          android:gravity="center" 
          android:src="@mipmap/ic_launcher"/> 
        </item> 
    
    </layer-list> 
    
  2. 现在你需要更新RES /价值/ styles.xml

    <resources> 
    
        <!-- Base application theme. --> 
        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
         <!-- Customize your theme here. --> 
        </style> 
    
    <style name="SplashTheme" parent="AppTheme"> 
         <item name="android:windowBackground">@drawable/splash_screen</item> 
        </style> 
    
    </resources> 
    
  3. 现在打开AndroidManifest.xml中和MainActivity

    <activity 
         android:name=".MainActivity" 
         android:label="@string/app_name" 
         android:theme="@style/SplashTheme" 
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"> 
         <intent-filter> 
          <action android:name="android.intent.action.MAIN" /> 
          <category android:name="android.intent.category.LAUNCHER" /> 
         </intent-filter> 
    </activity> 
    
    SplashTheme取代AppTheme

    我们使用SplashTheme而不是更新AppTheme,添加此背景仅用于启动活动并将其他stuf f没有改变。

  4. 不要忘记为你的根视图设置背景。这是因为Splash屏幕始终处于您的js视图之下。所以如果没有设置背景,它将是可见的。

0

你尝试使用this?几天前我遇到了这个问题。在iOS上运行良好,但我还没有在Android上测试它。 您应该安装节点> = 6并安装imageMagic。 (适用于Mac:brew install imagemagic

npm install -g yo generator-rn-toolbox 
yo rn-toolbox:assets --splash IMGAE --android 
相关问题