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

Ema*_*cco 1 android splash-screen react-native

当我按照那里所说的进行库的设置时: 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";
    }
}

Run Code Online (Sandbox Code Playgroud)

所以我尝试在 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";
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译时,它给了我这个错误:error: cannot find symbol variable SplashScreen

有人知道该怎么做吗?

Onl*_*ame 6

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

@Override
    protected void onCreate(Bundle savedInstanceState){
        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
    }
Run Code Online (Sandbox Code Playgroud)

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