解决Android应用冷启动时出现的白屏问题的方法
作者:阳春面 时间:2023-12-16 02:57:36
Android 应用冷启动时,需要从Application开始启动,加载时间就会比较长,容易出现白色或黑色闪屏,观察一下手机上一些 其他APP 比如 微信、京东等就不存在这个现象。
原因分析
分析一下原因,其实是跟闪屏Activity的主题有关,比如使用了Theme.AppCompat.Light.DarkActionBar主题的话,其中指定了windowBackground,所以背景就是白色的了。
<itemname="android:windowBackground">@color/background_material_light</item>
解决方案
设置Theme
我们需要在 manifest指定SplashActivity的theme
<activity
android:name=".SplashActivity"
android:theme="@style/AppTheme.Splash">
...
</activity>
设置 Style 背景图片
<style name="AppTheme.Splash" parent="AppTheme">
<item name="android:windowBackground">@mipmap/splash</item>
<item name="android:windowNoTitle">true</item>
</style>
这个style只是用来做闪屏的主题,APP的默认主题还是使用AppTheme
这种设置后默认先是出现APP内置的闪屏图片,然后在SplashActivity中再动态加载在线闪屏,最后进入主界面。最终实现效果与京东的APP类似。
来源:http://www.jianshu.com/p/9dac5e59ea49?utm_source=tuicool&utm_medium=referral
标签:android,冷启动,白屏
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Gradle的缓存路径修改的四种方法(小结)
2021-11-09 11:05:51
![](https://img.aspxhome.com/file/2023/4/130424_0s.png)
c#实现用SQL池,多线程定时批量执行SQL语句的方法
2023-12-25 01:03:55
通过特性(attribute)为枚举添加更多信息示例
2023-10-10 09:22:06
Java链表(Linked List)基本原理与实现方法入门示例
2021-10-12 05:49:14
![](https://img.aspxhome.com/file/2023/4/60824_0s.png)
Java实现简单GUI登录和注册界面
2022-09-02 06:36:21
![](https://img.aspxhome.com/file/2023/2/68202_0s.jpg)
C#中WebBrowser.DocumentCompleted事件多次调用问题解决方法
2023-12-05 18:23:15
C#中感叹号(!) 的作用总结
2021-10-14 15:08:12
![](https://img.aspxhome.com/file/2023/1/116551_0s.png)
eclipse maven 插件的安装和配置详解
2023-08-24 16:57:01
![](https://img.aspxhome.com/file/2023/8/58298_0s.jpg)
Android自定义ViewGroup多行多列效果
2022-10-31 06:07:17
![](https://img.aspxhome.com/file/2023/2/139352_0s.jpg)
教你怎么用Java获取国家法定节假日
2021-05-24 01:16:04
Java基础知识之StringWriter流的使用
2023-01-19 00:47:52
Android 用 camera2 API 自定义相机
2023-04-30 11:29:37
![](https://img.aspxhome.com/file/2023/2/139532_0s.jpg)
Java聊天室之解决连接超时问题
2021-06-07 16:30:54
![](https://img.aspxhome.com/file/2023/5/69115_0s.png)
详解Java中的JDK、JRE、JVM
2023-07-10 04:38:50
C#隐式运行CMD命令(隐藏命令窗口)
2023-05-03 17:41:32
![](https://img.aspxhome.com/file/2023/8/111218_0s.png)
Mybatis-plus自定义SQL注入器查询@TableLogic逻辑删除后的数据详解
2023-04-09 22:36:45
Java实战项目之校园跑腿管理系统的实现
2023-11-11 10:29:09
![](https://img.aspxhome.com/file/2023/9/104009_0s.jpg)
Java 调用Restful API接口的几种方式(HTTPS)
2021-06-19 02:26:55
启用springboot security后登录web页面需要用户名和密码的解决方法
2022-01-29 06:12:07
![](https://img.aspxhome.com/file/2023/9/92709_0s.png)
Android视频悬浮窗口实现的示例代码
2022-08-01 06:50:33
![](https://img.aspxhome.com/file/2023/6/138386_0s.gif)