我尝试将闪屏添加到我的 React Native 项目中。 我使用这个 npm 包“react-native-splash-screen”。 根据这个npm包,我将MainActivity.java文件更改为:
//splash screen
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
// splash screen
@Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
super.onCreate(savedInstanceState);
}
protected String getMainComponentName() {
return "ABC";
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new DefaultReactActivityDelegate(
this,
getMainComponentName(),
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
DefaultNewArchitectureEntryPoint.getFabricEnabled());
}
}
所以,这给了我一个错误:
error: cannot find symbol
protected void onCreate(Bundle savedInstanceState) {
^
symbol: class Bundle
location: class MainActivity
您需要在 MainActivity.java 文件顶部添加
import android.os.Bundle;
import android.os.Bundle; // <- Add this line
import org.devio.rn.splashscreen.SplashScreen;
...