为什么 Android WebView 拒绝用户输入? [英] Why is Android WebView refusing user input?

查看:25
本文介绍了为什么 Android WebView 拒绝用户输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Android 应用程序,它使用 WebView 来显示 Facebook 的登录页面.页面加载精美,我可以选择用户名/密码文本框,但输入它们不起作用.也就是说,它们肯定有输入焦点(它们有橙色的焦点突出显示框和一个闪烁的光标),但是输入它们绝对没有任何作用.我不确定,但我认为也许表单按钮也在播放 - 它们似乎只是刷新页面,而不是提交表单.

I'm developing an Android application that uses a WebView to display the login page for Facebook. The page loads beautifully, and I'm able to select the username/password textboxes, but typing in them will not work. That is, they definitely have input focus (they have the orange focus highlight box and a flashing cursor), but typing in them does absolutely nothing. I'm not certain, but I think maybe the form buttons are also playing up - they appear to be simply refreshing the page, rather than submitting the form.

需要说明的是,虽然我对让 Facebook 运行特别感兴趣,但我确信这不是 Facebook 的问题,因为其他网站(谷歌等)也表现出相同的行为.

Just to be clear, although I'm particularly interested in getting Facebook running, I'm sure that this isn't a Facebook issue since other websites (Google, etc) also display the same behavior.

有人知道可能是什么问题吗?

Does anyone have any ideas what might be the issue?

推荐答案

事实证明,问题显然是 WebView 没有获得焦点.

Turns out that it was apparently the WebView not having focus that was the issue.

我发现使用箭头键将焦点放在文本框上会导致它们工作,所以我推测某处存在问题,没有焦点,很可能是 WebView 没有焦点.果然,添加以下行似乎解决了问题:

I discovered that using the arrow keys to get focus on the textboxes caused them to work, so I theorised that there was an issue somewhere with something not having focus, most likely the WebView not having focus. Sure enough, adding the following line seemed to fix the problem:

webView.requestFocus(View.FOCUS_DOWN);

我仍然无法解释为什么会首先出现问题——文本框应该可以工作,无论它们是通过点击还是通过箭头"获得焦点——但至少我有一个解决方案似乎工作.

I'm still at a loss to explain exactly why the issue occurred in the first place - the textboxes should work whether they receive focus from being tapped upon or through being "arrowed" to - but at least I have a solution that appears to work.

感谢您的输入 wf.

这篇关于为什么 Android WebView 拒绝用户输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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