React Native 0.60.5 react-native-splash-screen配置Android

时间:2019-08-23 14:37:11

标签: android react-native react-native-android splash-screen

在我进行库设置时,遵循那里的说法:https://github.com/crazycodeboy/react-native-splash-screen 我发现在MainActivity.java中,不再有onCreate方法。

MainActivity.java RN 0.60

package com.testApp;

import com.facebook.react.ReactActivity;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "testApp";
    }
}

因此,我尝试在getMainComponentName方法中进行设置: MainActivity.java

package com.testApp;

import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */

    @Override
    protected String getMainComponentName() {
        SplashScreen.show(this);
        return "testApp";
    }
}

但是当我尝试编译时,出现此错误:error: cannot find symbol variable SplashScreen

有人知道怎么做吗?

1 个答案:

答案 0 :(得分:4)

重写MainActivity内部的onCreate方法,如下所示:

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

别忘了import android.os.Bundleimport org.devio.rn.splashscreen.SplashScreen;