消除 activity 启动时白屏、黑屏问题

这种问题一般是因为一个Activity启动之后在显示视图之间时间太长导致的。

1、优化方式可以通过精简layout文件、多线程处理数据载入等。

2、但是有些Activity的layout文件可能比较大,如果不能动态载入,在显示之前解析xml的时间可能耗时比较长比如500-1000ms。

这个时候Activity会先显示默认的黑色背景图,所以会出现黑屏的情况。对于这种情况我们可以在Application的Theme中添加

 "android:windowIsTranslucent">true 

将默认的窗口背景设置为透明色,这样就不会出现黑屏了。



默认情况下 activity 启动的时候先把屏幕刷成白色,再绘制界面,绘制界面或多或少有点延迟,这段时间中你看到的就是白屏,显然影响用户体验,怎么消除呢?


在 Activity theme 设置style 即可


[html]  view plain copy
  1. <style name="AppTheme" parent="android:Theme.Light.NoTitleBar">  
  2.     <item name="android:windowIsTranslucent">trueitem>  
  3.     <item name="android:windowNoTitle">trueitem>  
  4.     <item name="android:windowActionBar">falseitem>  
  5.       
  6. style>  


[html]  view plain copy
  1. <application  
  2.         android:name="com.skymobi.moposns.MyApplication"  
  3.         android:allowBackup="true"  
  4.         android:icon="@drawable/ic_launcher"  
  5.         android:label="@string/app_name"  
  6.         android:theme="@style/AppTheme" >  
  7.         <activity  
  8.             android:name="com.skymobi.moposns.MainActivity"  
  9.             android:label="@string/app_name"  
  10.             android:screenOrientation="portrait" >  
  11.             <intent-filter>  
  12.                 <action android:name="android.intent.action.MAIN" />  
  13.   
  14.                 <category android:name="android.intent.category.LAUNCHER" />  
  15.             intent-filter>  
  16.         activity>  

你可能感兴趣的:(Android)