输入法adjustResize 遮挡问题 (webview输入法遮挡问题处理)

输入法遮挡问题

解决输入法遮挡的问题 基本上有两种

adjustResize + ScrollView
adjustPan
adjustPan会把页面整体上推

adjustResize则是缩放可调整页面 所以要和ScrollView配合 但是如果界面设成全屏模式就不会生效

具体什么情况下失效,我没怎么验证。建议直接使用 adjustPan,就肯定失效了。

解决方法

方法1:获取界面可用高度,如果软键盘弹起后,Activity的xml布局可用高度需要减去键盘高度

方法2:增加一个白屏布局,获取高度,设置高度,更靠谱好用

ViewCompat.setOnApplyWindowInsetsListener(view, new OnApplyWindowInsetsListener() {
    @Override
    public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
        // ime // 软键盘
        Insets imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime());
        int height = imeInsets.bottom;
        int top = imeInsets.top;
        YZJLog.d("im-baseFold", "imeInsets height = " + height + ", top = " + top);

        Insets navigationBars = insets.getInsets(WindowInsetsCompat.Type.navigationBars());
        YZJLog.d("im-baseFold", "navigationBars height = " + navigationBars.bottom + ", top = " + navigationBars.top);

        try {
            height = height - navigationBars.bottom;
            if (list != null && list.size() > 0) {
                for (IWindowInsetsListener windowInsetsListener : list) {
                    windowInsetsListener.onKeyboardShown(height > 0 ? height : 0);
                }
            }
        } catch (Exception e) {

        }
        return insets;
    }
});

参考:
https://www.ngui.cc/el/1482026.html?action=onClick
http://www.manongjc.com/detail/54-nvnxfsozfsoxpuy.html
WindowInsetsCompat的浅识
https://blog.csdn.net/SOHU_TECH/article/details/126397570

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值