Why is Android WebView refusing user input?

前端 未结 16 1812
半阙折子戏
半阙折子戏 2020-11-28 08:12

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

相关标签:
16条回答
  • 2020-11-28 08:44

    I encountered this problem because I am displaying a splash image while the webview is loading the first page. I am setting the webview to View.VISIBLE in onPageFinished, however despite being able to focus text boxes you can't type into them. I too can confirm that the fix to set the webview requestFocus to View.FOCUS_DOWN works.

    NB. If I set the webview to View.VISIBLE in onResume the problem does not present itself but in my case the splash image disapears too soon.

    0 讨论(0)
  • 2020-11-28 08:46

    I'm sorry to say that none of this worked for me. I guess this depends on your context. In my case, the problem occurred within a html pop up (absolute div). All the other input field were doing ok.

    Breaking down the problem I found out it's a bug in the webview. Fixed positioned divs containing other fixed/absolute position divs break input fields in the page. Hence a rule I worded for you (don't hesitate to reformulate):

    If in your page you've got a fixed positioned div with none-default positioned nested divs (i.e. absolute, fixed, etc.), any of the following absolute positioned div in your page containing input fields will get the unexpected behaviour.

    So, put your input fields at the top of the page (if you can) or avoid absolute divs nested in other fixed/absolute divs. That should help.

    I posted something about it on my blog if you need more explanations and potential workarounds: http://java-cerise.blogspot.com/2012/02/android-web-view-inputfields-refuse-to.html

    0 讨论(0)
  • 2020-11-28 08:46

    It also happened in my project. I tried all above methods, none of them can effective. Finally, I solved this problem by use a dialog theme activity replaced the native Dialog. Hope this can help someone!

    0 讨论(0)
  • 2020-11-28 08:52

    Not sure if it's the problem since other websites also display the same behavior, but have you enabled javascript? A WebView does not enable it by default.

    WebView webView = (WebView)findViewById(R.id.yourWebView);
    webView.getSettings().setJavaScriptEnabled(true);
    
    0 讨论(0)
提交回复
热议问题