本文共 1219 字,大约阅读时间需要 4 分钟。
安卓启动时出现白屏,是因为在执行onCreate时占用了时间。而使用setContentView又一定要放在onCreate中,setContentView本身,就需要占用时间,所以这个白屏无法从根本上消除。
这个白屏是由activity的theme项来决定,学名Preview,,消除的方法,是继承系统给定的样式,添加
1 | < item name = "android:windowDisablePreview" >true</ item > |
禁用其预览页。。
当然,也可以通过
1 | < item name = "android:windowBackground" ></ item > |
来指定显示的背景页。
全部继承方式距离
1 2 3 4 | < style name = "AppTheme" parent = "AppBaseTheme" > <!-- All customizations that are NOT specific to a particular API-level can go here. --> < item name = "android:windowDisablePreview" >true</ item > </ style > |
注意:如果通过windowsBackground设置背景图后,在以后设计布局的时候,如果你没有给某个区域指定背景色,那么该区域默认透明,将会将背景图透视到前台。
在补充几个继承或者自定义主题时有用的Theme项,,(取自themes.xml)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // 背景图 <item name= "windowBackground" >@android:drawable/dark</item> // 前景图 <item name= "windowFrame" >@ null </item> // 是否展示标题 <item name= "windowNoTitle" > false </item> // 是否全屏 <item name= "windowFullscreen" > false </item> // 是否为悬浮窗 <item name= "windowIsFloating" > false </item> // 是否显示用户的壁纸 <item name= "windowShowWallpaper" > false </item> // 动画样式(说白了就是activity切换的动画) <item name= "android:windowAnimationStyle" ></item> |
1 2 3 | // 让背景透明, // 在activity左右滑动时,划出区域显示下方的窗口 <item name= "android:windowIsTranslucent" > true </item> |
转载地址:http://mzaym.baihongyu.com/