APP开发----启动闪屏的解决办法

闪屏的原因主要是我们启动Activity的时候,需要跑完onCreate和onResume才会显示界面。也就是说需要处理一些数据后,才会显示。按照这种思路,是不是我把初始化的工作尽量减少就可以避免黑屏?事实是,就算你onCreate啥都不做,仍然会闪一下黑屏,因为初始化解析界面时需要一定时间。下面是解决办法:

一.自定义Theme

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

二.修改AndroidManifest.xml

<applicationandroid:allowBackup="true"android:icon="@drawable/ipod_icon"android:label="@string/app_name"android:launchMode="singleTask"><!-- iPod主界面 --><activityandroid: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>
//......
</applicat





原文地址:https://www.cnblogs.com/wisemen/p/5821338.html