我有一个问题SplashScreenActivity
,当我在手机上启动我的应用程序时,它会显示大约 0.5 秒的白屏。MainActitivy
扩展FragmentActivity
并在I中AndroidManifest
声明SplashScreenActivity
为启动器和纵向模式为screenOrientation
.
编码:
public class SplashScreenActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splashscreen);
randomSplash();
Thread splashscreen = new Thread() {
public void run() {
try {
Thread.sleep(1000);
Intent mainScreen = new Intent("com.rm.jkrm.MAINACTIVITY");
startActivity(mainScreen);
} catch (InterruptedException e) {
} finally {
finish();
}
}
};
splashscreen.start();
}
private void randomSplash(){
Random random = new Random();
int i = random.nextInt(4);
LinearLayout ln = (LinearLayout) findViewById(R.id.splashscreen);
switch(i){
case 1:
ln.setBackgroundResource(R.drawable.splash1);
break;
case 2:
ln.setBackgroundResource(R.drawable.splash2);
break;
case 3:
ln.setBackgroundResource(R.drawable.splash3);
break;
default:
ln.setBackgroundResource(R.drawable.splash0);
break;
}
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/splashscreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>