Android的软键盘隐藏CordovaWebView投入在全屏模式下的时候 [英] Android soft keyboard hides inputs from CordovaWebView when in fullscreen

查看:1077
本文介绍了Android的软键盘隐藏CordovaWebView投入在全屏模式下的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CordovaWebView是presents一些HTML表单。当我专注于一个输入领域,Android的软键盘弹出,对于某些领域,根据自己的位置,它就会在它的上面。基本上,它是不调整CordovaWebView的布局。

I have a CordovaWebView that presents some html forms. When i focus on an input field, the Android's soft keyboard pops up and, for certain fields, according to their position, it gets on top of it. Basically, it is not resizing the layout of CordovaWebView.

无论我做什么,我不能改变这一点,据说,这是关系到一个事实,即CordovaWebView处于全屏模式。

Whatever i do, i can't change this, and it is said that it is related to the fact that the CordovaWebView is in fullscreen mode.

我如何能做到为解决此问题?

How can i accomplish to resolve this?

PS:是,还是不行,错误

PS: is it, or not, a bug?

感谢大家!

推荐答案

其实,这是一个众所周知的缺陷,如@ user2493245说。但是,我发现了一个解决办法,至少就我的具体情况。

In fact, it is a well know bug, as @user2493245 said. But I found a workaround, at least regarding my specific case.

上的WebView,只是检查了视图的可见区域的坐标。

on WebView, just check for the coordinates for the View's visible area.

final View activityRootView = this.root;
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
    public void onGlobalLayout() {
        Rect r = new Rect();
        //r will be populated with the coordinates of your view that area still visible.
        activityRootView.getWindowVisibleDisplayFrame(r);

        int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
        if(heightDiff != lastValue) {
            if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                appView.sendJavascript("onKeyBoardShow(" + r.bottom + ");");
            } else {
                appView.sendJavascript("onKeyBoardHide();");
            }
            lastValue = heightDiff;
        }
     }
});  

正如你所看到的,我发信息给web视图。在HTML中,我有这两种方法来处理这​​个问题:

As you can see, I send that information to the WebView. On HTML, I have this two methods to handle the issue:

function onKeyBoardShow(bottom) {
    var diff = ($('input[type=text]:focus').offset().top - bottom) + 50;
    if(diff > 0) {
        $('body').css("top", (diff * -1) + "px");
    }
};

function onKeyBoardHide() {
    $('body').css("top", "0px");
};

基本上,onKeyBoardShow,它得到的输入字段集中并计算像素,将需要移动体的量,从而使用户可以查看该输入字段。 onKeyBoardHide,简单地把主体到其原始位置。

Basically, onKeyBoardShow, it gets the input field focused and calculates the amount of pixels that will be necessary to move the body, allowing the user to see the input field. onKeyBoardHide, simply puts the body to its original position.

PS:这只是功能当视目标devicedpi,因为我们需要改变我们的方式获取有关该设备的DPI的DIF

PS: This only functions when the viewport targets devicedpi, as we need to modify the way we get the dif regarding the dpi of the device.

PS2:中code首先量不是我的,我只是编辑以满足我的需求。我看到一个SO问题,但可惜的是,现在我找不到它。如果我找到它,我会在这里发布的链接。

PS2: First amount of code is not mine, I only edited to fill my needs. I saw that on a SO question, but unfortunatelly now i can't find it. If i find it, i'll post the link here.

这篇关于Android的软键盘隐藏CordovaWebView投入在全屏模式下的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆