Android 启动页黑屏/白屏

黑白屏问题的原因


activity生命周期先执行onResume()方法,如果此方法中执行了耗时操作,阻塞了主线程,很明显就会出现黑白屏问题.还有就是即使onResume()方法没有执行还是会出现黑白屏问题,原因就是onCreate()中的下面这行代码是个异步任务,加载界面需要短暂的时间
 

解决方法

1.启动页面设置主题

<!-- 透明activity -->
<style name="bottomactivityTheme"  parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
</style>


2.配置文件中

<activity
    android:name=".index.SplashActivity"
    android:screenOrientation="portrait"
    android:theme="@style/bottomactivityTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

猜你喜欢

转载自blog.csdn.net/GodnessIsMyMine/article/details/85101960