android 全屏 webview 加载的h5的输入框,被键盘遮挡的解决

 安卓加载h5 ,h5界面有输入框 ,安卓键盘会被遮住 。

我是在全屏的状态下 这样设置有效(亲测)

class CustomLinearLayout: LinearLayout {
    constructor(context: Context?): super(context) {

    }

   constructor(context: Context?, attrs: AttributeSet?):  super(context, attrs) {

    }

   constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr) {

    }


    override fun fitSystemWindows(insets: Rect): Boolean {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            insets.left = 0
            insets.top = 0
            insets.right = 0
        }
        return super.fitSystemWindows(insets)
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
    override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets? {
        return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            super.onApplyWindowInsets(
                insets.replaceSystemWindowInsets(
                    0,
                    0,
                    0,
                    insets.systemWindowInsetBottom
                )
            )
        } else {
            insets
        }
    }
}

 

此处是ktlion代码

 

public class CustomLinearLayout extends LinearLayout {
    public CustomLinearLayout(Context context) {
        super(context);
    }

    public CustomLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

  

    @Override
    protected boolean fitSystemWindows(Rect insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            insets.left = 0;
            insets.top = 0;
            insets.right = 0;
        }
        return super.fitSystemWindows(insets);
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom()));
        } else {
            return insets;
        }
    }
}

此处是java代码 我都贴出来 害怕有些人看不懂kotlin 

更改布局的第一个节点 替换为自定义的类

AndroidManifest不用设置什么

希望能帮到各位

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我想吃辣条

觉得不错,就可怜可怜博主吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值