2016-01-27 61 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 
相關問題