【发布时间】:2017-08-02 13:16:44
【问题描述】:
我有一个启动画面,它只在应用程序重新启动时显示。如果用户点击返回按钮并再次启动应用程序,则不会显示启动画面。到这里为止一切都很好,如果没有显示启动画面,则打开应用程序时会出现 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();
}
我该如何解决这个问题?
【问题讨论】:
-
试试这个:
android:theme="@android:style/Theme.Translucent"在你的manifest.xml