Android 解决程序启动时的黑屏问题

来源:互联网 发布:linux解压和压缩命令 编辑:程序博客网 时间:2024/04/19 23:40
 关于黑屏默认的情况下,程序启动时,会有一个黑屏的时期,原因是,首个activity会加载一些数据,比如初始化列表数据、向服务器发送请求获取数据等等。去除方法:
1、在style里面添加一个style:

  1. <style name="ContentOverlay"parent="@android:style/Theme.Light"><itemname="android:windowNoTitle">true</item>
  2. <itemname="android:windowIsTranslucent">true</item>
  3. <itemname="android:windowContentOverlay">@null</item>
  4. </style>
复制代码
2、将主题设置到启动activity的主题里面

  1. <application
  2. android:icon="@drawable/icon"
  3. android:label="@string/app_name"
  4. android:name=".TWeiboApplication"
  5. android:debuggable="true"
  6. android:theme="@style/ContentOverlay">
  7. <activity
  8. android:name=".MainSplashActivity"
  9. android:configChanges="keyboardHidden|orientation"
  10. android:theme="@style/ContentOverlay">
  11. <intent-filter>
  12. <actionandroid:name="android.intent.action.MAIN"/>
  13. <categoryandroid:name="android.intent.category.LAUNCHER"/>
  14. </intent-filter>
  15. </activity>
复制代码
android 界面切换黑屏处理从A切换到B的过程中出现黑屏,可以在Manifest文件中改变B的theme,在theme里添加<item name="android:windowIsTranslucent">true</item>,这样从A到B的过程中,因为B是透 明的,所以背景就是A。这样的用户体验比较好。

原创粉丝点击