Android 启动白屏或者黑屏闪现解决

1、设置Style

 

 

 //1、设置背景图Theme

1 <style name="Theme.AppStartLoad" parent="android:Theme">  
2   <item name="android:windowBackground">@drawable/ipod_bg</item>  
3   <item name="android:windowNoTitle">true</item>  
4 </style>

 

//2、设置透明Theme

1 <style name="Theme.AppStartLoadTranslucent" parent="android:Theme">  
2   <item name="android:windowIsTranslucent">true</item> 
3   <item name="android:windowNoTitle">true</item>  
4 </style>

上面我定义了两种Theme,第一种Theme就是设置一张背景图。当程序启动时,首先显示这张背景图,避免出现黑屏。第二种Theme是把样式设置为透明,程序启动后不会黑屏而是整个透明了,等到界面初始化完才一次性显示出来。下面说说两种方式的优缺点:

  • Theme1 程序启动快,界面先显示背景图,然后再刷新其他界面控件。给人刷新不同步感觉。
  • Theme2 给人程序启动慢感觉,界面一次性刷出来,刷新同步。

2、修改AndroidManifest.xml

为了使上面Theme生效,我们需要设置一些Activity的Theme

 1 <application
 2   android:allowBackup="true"
 3   android:icon="@drawable/ipod_icon"
 4   android:label="@string/app_name"
 5   android:launchMode="singleTask">
 6 
 7 <!-- iPod主界面 -->
 8 <activity
 9   android:name="com.apical.apicalipod.IPodMainActivity"
10   <!-- 使用上面定义的样式 mythou-->
11   android:theme="@style/Theme.AppStartLoad"
12   android:label="@string/app_name" >
13   <intent-filter>
14   <action android:name="android.intent.action.MAIN" />
15   <category android:name="android.intent.category.LAUNCHER" />
16   </intent-filter>
17 </activity>
18 
19 //......
20 
21 </application>

 

posted @ 2016-09-25 17:04  火龙裸先生  阅读(637)  评论(0编辑  收藏  举报