一.白屏及黑屏产生的原因:
当Activity启动的时候不能马上加载layout。而黑屏或者白屏是AppTheme的默认样式,代码如下:
@color/background_material_light
具体颜色值为:#fffafafa
于是,当layout还没加载完成的时候就会显示相应的主题颜色(黑/白屏)。
二.解决方案:
1.像微信那样,把启动页的窗口背景设为透明。这样,当点击app图标时,因为背景是透明的,所以看不到
任何东西,等layout完全加载好了就可以看到真正的界面了。
a.先设置style:
@android:color/transparent
true
b.在启动activity加入该Theme:
android:theme="@style/SplashTheme.Translucent">
c.千万别忘了在真正的layout添加非透明的背景色,不然界面显示时是透明的:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
......
2.把启动页的主题背景换成图片。当点击app图标时,在layout加载完毕之前都是显示这张背景图片。
当layout加载完毕之后,背景图片才消失,同时显示真正的界面。
a.先设置style:
@drawable/welcome
false
b.在启动activity加入该Theme:
android:theme="@style/SplashTheme.NotTranslucent">
c.千万别忘了在真正的layout添加非透明的背景色,不然界面显示时依然能看到欢迎页那张图片:
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
......