当前位置: 代码迷 >> 综合 >> 优化冷起白屏 splash背景图被虚拟键盘遮挡
  详细解决方案

优化冷起白屏 splash背景图被虚拟键盘遮挡

热度:5   发布时间:2024-01-28 21:47:06.0

前后效果图我就不展示了  这里大概描述一下   

优化前   点击应用图标  在应用splash之前  会有一个短暂的白屏时间   体验感觉不流畅  视觉效果不好

优化后  点击应用图标   直接展示splash页面的背景图(为啥我说是背景图   因为如果你的splash页面xml里面  不单单是一张图片  还有别的textview等  需要在layout里面设置的   这部分内容还是会延时展示   所以建议想展示啥   都做到图里)   

这个方法只是在显示时  用你splash的背景图来把白屏遮挡住   显得流畅  好看了   还有一部分优化是要优化Application里面的初始化流程  需要自己做哈

这个方法就是给splash设置主题   首先在style里面自定义一个theme

<style name="SplashThemeImage" parent="@android:style/Theme.Light.NoTitleBar.Fullscreen"><item name="windowActionBar">false</item><item name="windowNoTitle">true</item><item name="android:windowBackground">@drawable/splash_bg</item><!--沉浸--><item name="android:windowTranslucentStatus">true</item></style>

然后设置给splash

    <activityandroid:name="SplashActivity"android:screenOrientation="portrait"android:theme="@style/SplashThemeImage"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity>

这里说一下这个parent   theme为啥选用的这个 

@android:style/Theme.Light.NoTitleBar.Fullscreen

 最开始我是用的Theme.AppCompat.Light.NoActionBar  但是设置完成之后白屏解决了   但是有个问题  就是如果我这个页面底部有字或者别的信息   当前手机又是虚拟按键的话   底部部分会被虚拟按键展示   用的上面的的这个theme   就解决了这个问题

这里还有个要注意的  如果使用这种方式之后   splash里面就不要setContentView了  一个是功能冲突  有可能会有图片错位的情况 还有一个就是如果不设置 多少可以优化一下速度   虽然可能也就几毫秒或者十几毫秒  基本体验不到 

  相关解决方案