启动APP时出现白屏问题

最近发现APP启动时,会出现短暂的白屏,看了一下一些成熟的APP并没有这个情况.
百度并整理了一下.
这里记录一下:

首先,这是正常现象,因为当Activity生命周期走到OnResume()显示界面时,我们的Activity并没有加载到布局资源(OnCreate()->setContentView(R.layout.activity_launch_app)),所以肯定会有一个短暂的白屏时间.
这时显示的是window背景,显示的是黑屏白屏,取决于你的主题设置.

有两个解决方案:

1.自定义一个style,设置背景图,这时,当还没有加载到布局资源时,就会显示这张图片;
(项目中布局文件根布局不要写成透明,否则背景都是启动图)
    <style name="My_Start_Theme" parent="@android:style/你想使用的主题">
    <item name="android:windowBackground">@drawable/启动页的图片名</item>
    <item name="android:windowNoTitle">true</item>
    </style>
打开AndroidManifest.xml  在<application 节点中 替换主题.


2.把windowBackground设置为透明,这样用户体验就是,我已经点击了这个APP,因为此时北极你个是透明的,给人一种启动延迟的感觉(去让用户怀疑手机卡顿),代码跟上一种同理.
    <style name="My_Start_Theme" parent="@android:style/Theme.NoTitleBar">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowNoTitle">true</item>
    </style>
下面是自定义主题Theme的一些属性,有兴趣的同学可以参考一下:
•android:theme="@android:style/Theme.Dialog"   将一个Activity显示为能话框模式  
•android:theme="@android:style/Theme.NoTitleBar"  不显示应用程序标题栏  
•android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  不显示应用程序标题栏,并全屏  
•android:theme="Theme.Light"  背景为白色  
•android:theme="Theme.Light.NoTitleBar"  白色背景并无标题栏   
•android:theme="Theme.Light.NoTitleBar.Fullscreen"  白色背景,无标题栏,全屏  
•android:theme="Theme.Black"  背景黑色  
•android:theme="Theme.Black.NoTitleBar"  黑色背景并无标题栏  
•android:theme="Theme.Black.NoTitleBar.Fullscreen"    黑色背景,无标题栏,全屏  
•android:theme="Theme.Wallpaper"  用系统桌面为应用程序背景  
•android:theme="Theme.Wallpaper.NoTitleBar"  用系统桌面为应用程序背景,且无标题栏  
•android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen"  用系统桌面为应用程序背景,无标题栏,全屏  
•android:theme="Translucent"  半透明  
•android:theme="Theme.Translucent.NoTitleBar" 半透明、无标题栏  
•android:theme="Theme.Translucent.NoTitleBar.Fullscreen" 半透明、无标题栏、全屏  
•android:theme="Theme.Panel"  
•android:theme="Theme.Light.Panel"  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值