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

posted @ 2020-06-05 11:09  哇哇·刘  阅读(786)  评论(0)    收藏  举报