android App启动闪白屏解决方案

xiaoxiao2025-10-20  9

App启动白屏/黑屏产生原因:

     进入到Activity,但是未加载到布局文件,就先显示来windows窗口的背景。黑屏/白屏就是显示的windows背景(这个就是theme的设置)。

    onCreate---setContentView这个并不是同时进行的,窗体绘制的第一步,系统会在执行这个步骤之前,先绘制窗体,这时候布局资源还没加载,于是就使用默认背景色。

解决方案:

第一种:设置一张背景图片(快速,流畅)

<style name="Theme.AppStartLoad" parent="android:Theme"> <item name="android:windowBackground">@drawable/tp</item> <item name="android:windowNoTitle">true</item> </style>

第二种:设置窗口透明(一次性加载成功)

<style name="Theme.AppStartLoadTranslucent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> </style>

意见建议:

建议采取第一种方式,微信呀,淘宝啥的都是用此方案解决

转载请注明原文地址: https://www.6miu.com/read-5038268.html

最新回复(0)