遇到的情况:

app启动时进入启动页时出现白屏页,然后大概一秒之后就出现了背景图片。

原因:app启动时加载的是windows背景,之后再加载布局文件的,所以开始的黑屏/白屏就是windows的背景颜色,因此我们只要在启动页设置windows背景颜色就好了,那么在哪里设置呢?  就是theme里面。

解决办法:参考:【Android Drawable 那些不为人知的高效用法

Android 启动APP时黑屏白屏的三个解决方案

首先看之前的布局文件xml写法

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:background="@drawable/bg_app_welcome_1"/>
<LinearLayout
android:id="@+id/v_prepare_tips"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#007ed2"
android:text="首次安装正在准备数据"/>
<ProgressBar
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>
</LinearLayout> </RelativeLayout>

=========================================================

优化之后的:

<!-- 只是将根元素的背景去掉了 -->
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/v_prepare_tips"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#007ed2"
android:text="首次安装正在准备数据"/>
<ProgressBar
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</RelativeLayout>

设置style.xml

    <style  name="AppStartingBg"  parent="@android:style/Theme.Holo.Light.NoActionBar" >
<item name="android:windowBackground">@drawable/bg_appstarting</item>
</style>
bg_appstarting.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<bitmap android:src="@drawable/bg_app_welcome_1" android:gravity="fill" />
</item>
</layer-list>

再在manifest.xml文件中添加该ancivity的theme

<activity
android:name="com.client.activity.AppStartingActivity"
android:icon="@drawable/ic_logo_2"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppStartingBg" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

大功告成!

最新文章

  1. js模块化历程
  2. Linux常用命令集合
  3. Nullable&lt;&gt;
  4. oop、configparser、xml模块
  5. ssh框架搭建错误集合
  6. python3读取文件
  7. 面试题总结之Database
  8. 《深度探索c++对象模型》chapter1关于对象对象模型
  9. ssh远程登录Ubuntu报错:Permission denied, please try again.
  10. BZOJ 2599 Race(树分治)
  11. 07_DICTIONARY_ACCESSIBILITY
  12. -webkit-filter是神马?
  13. maven-assembly-plugin插件的使用方法
  14. MySQL DATE_SUB()
  15. display:flex布局
  16. JNI NDK (AndroidStudio+CMake )实现C C++调用Java代码流程
  17. 设计模式C++学习笔记之十五(Composite组合模式)
  18. Android Studio xml文件中的布局预览视图
  19. Android工程中javax annotation Nullable找不到的替代方案
  20. html调用静态json例子

热门文章

  1. UIButton设置imgae图片自适应button的大小且不变形
  2. MySQL查询昨天、今天、7天、近30天、本月、上一月数据
  3. centos6.2下安装redis和phpredis扩展,亲测好用
  4. 控制不能离开Finally子句主体
  5. 在SQL中取出字符串中数字部分或在SQL中取出字符部分
  6. Vue.js学习 Item6 -- Class 与 样式绑定
  7. Nginx下10个安全问题提示
  8. php根据日期获得星期
  9. VMT &amp; DMT
  10. 倒水问题 (codevs 1226) 题解