使用InAppBrowser和微调器加载页面后无法输入输入字段 [英] Can't type in input field after loading a page with InAppBrowser and spinner loading

查看:65
本文介绍了使用InAppBrowser和微调器加载页面后无法输入输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常有趣的问题.我在我的一个Android应用程序中使用了inAppBrowser和spinner.Spinner通过 ProgressDialog 实现.这里的问题是,当我尝试通过inAppBrowser打开网页时,加载微调器在页面开始加载后开始加载,然后在完成页面加载后关闭,当我点击该页面的输入字段并尝试输入字母或数字,它只会停留在所谓的锁定"状态.如果输入的内容看不见,则光标会一直闪烁.

I'm having very interesting problem. I use inAppBrowser and spinner in one of my Android application. Spinner is implemented with ProgressDialog. The problem here is that when I try to open a web page through inAppBrowser and the loading spinner starts loading once the page start to load and then close once it has finished loading the page, when I tap on input field of that page and try to type letters or numbers, it just stays in that so called "locked" state. If I type something I can't see them, the cursor just keep blinking.

要使它变得更奇怪,我可以键入特殊字符.如果我点击页面周围的任何其他位置,然后再次点击该相同的输入字段,则它将起作用.另一种可行的情况是,我将应用程序置于暂停"状态,然后恢复它,则输入字段起作用.

To make this even more weird, I'm able to type special characters. If I tap to any other place around the page, then tap again to that same input field, then it works. Another case when it works is when I put the application into Pause status and then resume it, the input fields works.

仅在版本5.0.1和更低版本的Android平台中会发生此问题.

This problem occurs only in Android platforms of version 5.0.1 and older.

inAppBrowser Java文件可以在Github中的 InAppBrowser Java文件.

The inAppBrowser java file can be found in Github at InAppBrowser java file.

我的微调器实现如下:

spinner = new ProgressDialog(cordova.getActivity());
spinner.setIndeterminate(false);
spinner.setProgressStyle(ProgressDialog.STYLE_SPINNER);
spinner.setCancelable(false);
spinner.setMessage(cordova.getActivity().getText(R.string.spinner_loading));
spinner.setTitle("");

然后我通过以下方式显示/隐藏微调器:

and I show/hide a spinner with following way:

@Override
public void onPageStarted(WebView view, String url,  Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    //InAppBrowser default code....

    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_START_EVENT);
        obj.put("url", newloc);

        sendUpdate(obj, true);

    } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
    }

    spinner.show();
}

public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);
    try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_STOP_EVENT);
        obj.put("url", url);

        sendUpdate(obj, true);

    } catch (JSONException ex) {
         Log.d(LOG_TAG, "Should never happen");
    }

    spinner.hide();
}

这里可能是什么问题?任何提示,建议将不胜感激.

What could be the problem here? Any tips, suggestions would be appreciated.

推荐答案

现在我可以解决此问题.问题是该特定页面输入字段的焦点.由于某种原因,页面加载完成后,它并没有将重点放在自身上.

Now I was able to fix the problem. The problem was the focus of that specific page input field. For some reason it didn't got the focus on itself once the page has been finished of loading.

尝试通过使用 editText.clearFocus()然后再 editText.requestFocus()来解决inAppBrowser的 inAppBrowser.java 文件中的问题完全没有帮助.但是对我有用的是遵循解决方案.

Trying to fix the issue within inAppBrowser's inAppBrowser.java file by using editText.clearFocus() and then editText.requestFocus() didn't help at all. But what worked for me was following solution.

由于inAppBrowser具有名为 executeScript()的方法,因此我能够向出现此问题的特定输入字段注入一些Javascript代码.因此,下面的代码可以解决问题:

Since inAppBrowser has a method called executeScript(), I was able to inject some Javascript code to that specific input field that had this issue. Thus following code did the trick:

var ref = cordova.InAppBrowser.open('http://apache.org', '_blank',  location=yes');
ref.addEventListener('loadstop', function() {
    ref.executeScript({code: "$('#element').blur(); $('#element').focus();"});
});

该代码的作用是,它将首先清除该特定元素的焦点,然后再次聚焦于该相同元素.

What does that code do is that it will first clear the focus out of that specific element and then focus on that same element again.

无论版本如何,这都可以在任何平台上使用.

This turned to work on any platform regardless of the version which is big thing.

这篇关于使用InAppBrowser和微调器加载页面后无法输入输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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