fitsSystemWindows与软键盘冲突

一、现象
页面根布局,因为沉浸式效果设置了fitsSystemWindows=true,当页面上有输入框拉起键盘的时候,导致页面展示异常

二、修改
自定义根布局,重载onApplyWindowInsets,替换SystemWindowInsets

class FitConstraintLayout(context: Context, attributeSet: AttributeSet) : ConstraintLayout(context, attributeSet) {

    /**
     * 修复 fitsSystemWindows 与软键盘的冲突问题
     * */
    override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets {
        val copyInsets = insets?.let {
            val origin = WindowInsetsCompat.toWindowInsetsCompat(it)
            origin.replaceSystemWindowInsets(0, origin.systemWindowInsetTop, 0, 0)
        }
        return super.onApplyWindowInsets(copyInsets?.toWindowInsets()?:insets)
    }
}

三、结语

  1. 送人玫瑰 手留余香
  2. 如果对您有帮忙,请点赞支持我~~
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容