冷启动白屏

2021-05-23  本文已影响0人  Method
old.gif

白屏原因

应用冷启动需要创建应用进程,创建Application,创建主界面调用onCreate(),onResume,这一段时间内会出现白屏。App默认的windowbackground是白色的,所以会显示白屏。

解决方法

修改默认windowbackground

style

<!--首个页面style-->
    <style name="LauncherStyle" parent="Theme.HelloKotlin">
        <item name="android:windowBackground">@drawable/launcher_style</item>
    </style>

设置layer-list 防止图片拉伸

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--设置背景图层-->
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/white"/>
        </shape>
    </item>
    <!--设置闪屏图片-->
    <item android:gravity="center">
        <bitmap android:src="@drawable/gyy1"/>
    </item>
</layer-list>

设置theme

 <activity android:name=".statusbar.StatusBarActivity"
            android:theme="@style/LauncherStyle">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

复原theme

修改回原来的theme 否则window上会一直有个背景图

class StatusBarActivity:AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        /*设置回原theme*/
        setTheme(R.style.Theme_HelloKotlin)
        setContentView(R.layout.acy_status)
    }
}
new.gif
上一篇 下一篇

猜你喜欢

热点阅读