Android应用启动时的白色背景

cxp*_*ong 11 android android-layout

每当我的应用程序启动时,都会在短时间内显示白色背景.尽管使用了启动画面,问题仍然存在.我想将启动屏幕设置为黑色而不是默认的白色!

这是我的启动画面活动:

public class SplashActivity extends Activity {

private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 1;    // Sleep for some time

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
    setContentView(R.layout.splash);

    // Start timer and launch main activity
    IntentLauncher launcher = new IntentLauncher();
    launcher.start();
}

private class IntentLauncher extends Thread {

    /**
      * Sleep for some time and than start new activity.
      */ 
    @Override
    public void run() {
        try {
            // Sleeping
            Thread.sleep(SLEEP_TIME*1000);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }

        // Start main activity
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        SplashActivity.this.startActivity(intent);
        SplashActivity.this.finish();
    }

}

@Override
protected void onPause() {
    super.onPause();
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
}
Run Code Online (Sandbox Code Playgroud)

dju*_*nod 24

在styles.xml中,在AndroidManifest.xml中指定的主题中,添加以下行:

<item name="android:windowBackground">@android:color/black</item>
Run Code Online (Sandbox Code Playgroud)


Swe*_*r ツ 7

在清单中使用此标记:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
Run Code Online (Sandbox Code Playgroud)

代替 :

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)


der*_*ect 6

在drawable文件夹中,创建自己的starting_screen.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <!-- black background -->
            <solid android:color="@color/colorBlack" />
        </shape>
    </item>
    <!-- launcher icon -->
    <item android:drawable="@mipmap/ic_launcher_foreground" android:height="150dp" android:width="150dp" android:gravity="center" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)

然后将此添加到您的样式中

<item name="android:windowBackground">@drawable/starting_screen</item>
Run Code Online (Sandbox Code Playgroud)

现在,每当您启动应用程序时,都会出现带有启动器图标的黑屏