Android 启动应用出现黑屏闪现
闪黑屏的原因主要是我们启动Activity的时候,需要跑完onCreate和onResume才会显示界面。也就是说需要处理一些数据后,才
会显示。按照这种思路,是不是我把初始化的工作尽量减少就可以避免黑屏?但是我发现我的onCreate就只是加载了界面,仍然会闪
一下黑屏,因为初始化解析界面时需要一定时间。
2种方法:
1、给Theme 设置背景图。为 Theme 设置背景图后程序在启动的时候,会首先显示这张图,避免发生黑屏。
2、给 Theme 设置透明属性。程序启动后不会黑屏而是透明,等到界面初始化完成后才一次性显示出来。
application的Theme属性中加入一句代码就好:
res/values/themes.xml
<style name="GameNoActionBar" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
</style>
AndroidManifest.xml
<activity android:name="com.bjgjhb.kj.quick.SplashActivity"
android:exported="true"
android:theme="@style/GameNoActionBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>