【发布时间】:2020-03-30 03:22:00
【问题描述】:
我在我的应用中添加了启动画面。启动画面会加载,但会在应用加载前大约 5 秒变白。我想在应用启动之前一直保持启动画面。
我尝试在 this question 上关注 Sooraj 的回答,但他们没有提供任何关于他们的答案的解释,因为它写在问题上。不起作用的主要部分是setContentView(R.layout.activity_splash); 行,当我尝试构建我的应用程序时会产生错误。当我删除该行时,我的应用程序在安装后崩溃
MainActivity.java
package com.sealsounds;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import com.sealsounds.SplashActivity;
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 "SealSounds";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, SplashActivity.class);
startActivity(i);
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
}
SplashActivity.java
package com.sealsounds;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
public class SplashActivity extends ReactActivity {
private static int SPLASH_TIME_OUT = 5000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
finish();
}
}, SPLASH_TIME_OUT);
}
}
【问题讨论】:
-
在本机代码中出现闪屏的任何原因?
-
@VinayRevankar 不,我认为这是这样做的方法。我可能只是查错了东西
-
你可以自己在JS代码中实现。让我知道这是怎么回事
-
@VinayRevankar 我该怎么做?
-
使用切换导航
标签: android reactjs react-native splash-screen