gpt4 book ai didi

java - 打开应用程序时如何删除黑屏

转载 作者:行者123 更新时间:2023-11-29 07:29:07 25 4
gpt4 key购买 nike

我有一个闪屏,它只在应用程序重新启动时显示。如果用户点击后退按钮并再次启动应用程序,则不会显示启动画面。到这里为止一切都很好,如果不显示启动画面,打开应用程序时会有 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();
}

我该如何解决这个问题?

最佳答案

添加@Bryan 我向您推荐 cold start .例如我确实喜欢这个

在你的 Style.xml 中:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.splashScreenLauncher">
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

</style>

splash_screen.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="@android:color/white"/>

<item>
<bitmap
android:src="@drawable/SPLASHIMAGE"
android:gravity="center"/>
</item>
</layer-list>

在 list 中,您设置启动器 Activity 的地方:

android:theme="@style/AppTheme.splashScreenLauncher"> 

在您的启动器 Activity 中:

setTheme(R.style.AppTheme); // IMPORTANT BEFORE super.onCreate
super.onCreate(savedInstanceState);

关于java - 打开应用程序时如何删除黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45461987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com