前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >fitsSystemWindows与软键盘冲突

fitsSystemWindows与软键盘冲突

原创
作者头像
FangMessi
修改2021-09-28 18:21:00
1.1K0
修改2021-09-28 18:21:00
举报
文章被收录于专栏:码工非码码工非码

一、现象

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

二、修改

自定义根布局,重载onApplyWindowInsets,替换SystemWindowInsets

代码语言:txt
复制
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. 如果对您有帮忙,请点赞支持我~~

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、现象
  • 二、修改
  • 三、结语
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com