今天在app上发现activity在切换的时候,背景的图片顶部出现了白色的闪烁,起初还认为是actionbar的设置的背景图片引起的,后来网上搜索了一番,发现不少人也遇到了问题。最后定位就是activity设置的theme引起的,在activity中我设置的是light:
<!-- 相当于holo.light样式 -->
<style name="Theme.Mike.Light" parent="@style/Theme.AppCompat.Light">
<item name="android:windowContentOverlay">@null</item>
<item name="popupMenuStyle">@style/Widget.Mike.Light.PopupMenu</item>
<item name="textAppearanceLargePopupMenu">@style/TextAppearance.Mike.Light.Widget.PopupMenu.Large</item>
</style>
而Light 样式的 windowBackground、colorBackground、colorForeground 等属性的值均为 light 也就是白色偏亮,所以才会出现白色闪屏。
1、进行简单修改后:
<!-- 相当于holo.light样式 -->
<style name="Theme.Mike.Light" parent="@style/Theme.AppCompat.Light">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="popupMenuStyle">@style/Widget.Mike.Light.PopupMenu</item>
<item name="textAppearanceLargePopupMenu">@style/TextAppearance.Mike.Light.Widget.PopupMenu.Large</item>
</style>
将背景windowBackground和windowIsTranslucent设置transparent和true之后,发现白色的闪屏消失,似乎解决了问题,但是在有软键盘弹出的页面,由于两个属性都设置了透明,就导致了软键盘在收回去的一瞬间时候,出现了上个activity的背景图
2、再次修改:
<!-- 相当于holo.light样式 -->
<style name="Theme.Mike.Light" parent="@style/Theme.AppCompat.Light">
<item name="android:windowBackground">@color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="popupMenuStyle">@style/Widget.Mike.Light.PopupMenu</item>
<item name="textAppearanceLargePopupMenu">@style/TextAppearance.Mike.Light.Widget.PopupMenu.Large</item>
</style>
去掉windowisTranslucent之后,虽然没有闪屏出现,也没有出现上个activity的背景,但是键盘在弹出来的时候,键盘的window会有黑色的背景闪烁
3、最后就用了另外一个样式(或者将android:windowBackgroud的背景设置黑色,和下面的效果基本一样)
<style name="Theme.Mike" parent="@style/Theme.AppCompat">
<item name="android:windowContentOverlay">@null</item>
</style>
这样虽然看似可以,但是如果activity的背景是白色的,再切换的时候应该就会出现黑色的闪屏
也可以用background设置一个背景图,来解决,但是对我不是最好的解决方法
参考:http://blog.csdn.net/fancylovejava/article/details/39643449
http://www.cnblogs.com/sunzn/p/3407078.html