Android 啟動白屏或者黑屏閃現解決


1、設置Style


//1、設置背景圖Theme
<style name="Theme.AppStartLoad" parent="android:Theme">  
  <item name="android:windowBackground">@drawable/ipod_bg</item>  
  <item name="android:windowNoTitle">true</item>  
</style>
 //2、設置透明Theme 
<style name="Theme.AppStartLoadTranslucent" parent="android:Theme">  
  <item name="android:windowIsTranslucent">true</item> 
  <item name="android:windowNoTitle">true</item>  
</style>
 
        

上面我定義了兩種Theme,第一種Theme就是設置一張背景圖。當程序啟動時,首先顯示這張背景圖,避免出現黑屏。第二種Theme是把樣式設置為透明,程序啟動后不會黑屏而是整個透明了,等到界面初始化完才一次性顯示出來。下面說說兩種方式的優缺點:

  • Theme1 程序啟動快,界面先顯示背景圖,然后再刷新其他界面控件。給人刷新不同步感覺。
  • Theme2 給人程序啟動慢感覺,界面一次性刷出來,刷新同步。

2、修改AndroidManifest.xml

為了使上面Theme生效,我們需要設置一些Activity的Theme

<application
  android:allowBackup="true"
  android:icon="@drawable/ipod_icon"
  android:label="@string/app_name"
  android:launchMode="singleTask">

<!-- iPod主界面 -->
<activity
  android:name="com.apical.apicalipod.IPodMainActivity"
  <!-- 使用上面定義的樣式 mythou-->
  android:theme="@style/Theme.AppStartLoad"
  android:label="@string/app_name" >
  <intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

//......

</application>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM