我有一個啓動畫面,僅在應用程序的新開始時顯示。如果用戶點擊返回按鈕並再次啓動應用程序,則不顯示啓動畫面。一切都很好,直到這裏,如果飛濺不顯示,打開應用程序時有1-2秒的黑屏。這是我的splashactivity java文件;如何在打開應用程序時刪除黑屏¶
public class SplashScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("first_time", false)) // if first time, show splash
{
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_time", true);
editor.commit();
setContentView(R.layout.activity_splash);
Thread t = new Thread() {
public void run() {
try {
int time = 0;
while (time < 4000) {
sleep(100);
time += 100;
}
}
catch (InterruptedException e) {
// do nothing
}
finally {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}
};
t.start();
}
else // if not first time, dont show splash
{
setContentView(R.layout.activity_splash);
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
我該如何解決這個問題?
試試這個:'機器人:主題=「@機器人:樣式/ Theme.Translucent「'在'manifest.xml' –
同樣的問題試試這個https://stackoverflow.com/questions/8817568/how-to-avoid-black-screen-in-android-while-my-app -is-loading –