Android app启动出现白屏闪屏

出现白屏闪屏原因:

进入到AppStartActivity,但是未加载到布局文件,就先显示了窗口的背景,白屏就是显示的windows的背景,即所设置的theme。
onCreate()中的setContentView()和绘制窗体并不是同时进行的,系统会在执行setContentView()之前,先绘制窗体,这时候布局资源还没加载,于是就使用默认背景色。

直接上解决方法呀:👇👇👇

方法一:设置透明背景

第一步:在res的style中添加如下主题

   <!--启动页主题-->
    <style name="AppStartTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

第二步:应用在清单文件的启动页主题上

        <activity android:name="com.catherineliu.demo.main_code.MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/AppStartTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

不足:会使得点击app图标使给用户一种卡顿的感觉。

方法二:

第一步:在res的style中添加如下主题

    <!--启动页图片资源主题-->
    <style name="Theme.AppStartLoad" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/welcome_bac</item>
        <item name="android:windowNoTitle">true</item>
    </style>

第二步:

        <activity android:name="com.catherineliu.demo.main_code.MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/Theme.AppStartLoad">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

不足:会使得点击app启动页只能是一张图片,不能有多的布局。

注意:所写主题的parent需要为Theme.AppCompat下的主题,不能是parent="android:Theme",否则引用不到,会报错。

感谢:https://blog.csdn.net/woainijinying/article/details/83386010

查看更多:https://blog.csdn.net/u010351494/article/details/80034515

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值