在我进行库设置时,遵循那里的说法: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
有人知道怎么做吗?
答案 0 :(得分:4)
重写MainActivity内部的onCreate方法,如下所示:
@Override
protected void onCreate(Bundle savedInstanceState){
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
别忘了import android.os.Bundle
和import org.devio.rn.splashscreen.SplashScreen;