【问题标题】:White background when Android app start upAndroid应用启动时的白色背景
【发布时间】:2019-05-31 21:49:45
【问题描述】:

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

这是我的启动画面活动:

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);
}
}

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

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

    <item name="android:windowBackground">@android:color/black</item>
    

    【讨论】:

    • 如果我希望 ImageView 以这种样式显示怎么办?
    • 这就是我要找的。​​span>
    • 必须扩展 Activity 而不是 AppCompatActivity 然后将我的主题的父级设置为 "android:Theme.Material.Light.NoActionBar" 之前这对我有用
    【解决方案2】:

    在你的清单中使用这个标签:

    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    

    而不是:

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    【讨论】:

    • 在所有答案中,只有这个对我有用!谢谢!
    【解决方案3】:

    在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>
    

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

    <item name="android:windowBackground">@drawable/starting_screen</item>
    

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

    【讨论】:

      【解决方案4】:

      如果您想将初始屏幕之前出现的白屏更改为黑色,只需更改 SplashActivity 的主题,而不是整个应用。

      你可以用这个:

      <activity
          android:name="your.package.SplashActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
      </activity>
      

      希望这会有所帮助。

      【讨论】:

        【解决方案5】:

        您可以使用自定义主题更改启动窗口的背景颜色。示例见Styles and Themes

        【讨论】:

          【解决方案6】:

          在styles.xml中,为SplashActivity申请的主题,添加如下一行

          <item name="android:windowBackground">@drawable/background</item>
          

          @drawable/background 是您为启动画面应用的背景,也可以是您需要的任何颜色。

          【讨论】:

            【解决方案7】:

            您在活动开始时设置了 splash.xml。更改它,将父背景更改为黑色或您想要的任何颜色。它会起作用,或者将 splash.xml 主题更改为 holo_dark 或任何其他主题

            【讨论】:

              猜你喜欢
              • 2013-01-05
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2022-11-21
              • 1970-01-01
              • 2021-09-10
              相关资源
              最近更新 更多