2013-11-02 47 views
6

每次我的應用程序啓動時,都會在短時間內顯示白色背景。 儘管使用啓動畫面,問題仍然存在。 我想將默認啓動屏幕設置爲黑色而不是白色!Android應用程序啓動時的白色背景

這是我潑的屏幕活動:

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

回答

6

使用該標籤在你的清單:代替

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

this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
+0

謝謝!那很好! – cxphong

+1

非常好 - 謝謝! – gnB

0

當你的活動開始時,你已經設置了splash.xml。改變這一點,改變父母的背景爲黑色或任何顏色你wan。它將工作,或將splash.xml主題更改爲holo_dark或任何其他主題

3

如果要將啓動屏幕之前出現的白色屏幕更改爲黑色,只需更改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> 

希望這有助於。

9

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

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

完美謝謝 –

+0

如果我想要以這種風格顯示ImageView,該怎麼辦? – grant

+0

這就是我一直在尋找的東西。 – Klevi01

相關問題