在 AlertDialog 中显示软键盘,其中包含 WebView (Android) [英] Show soft keyboard in AlertDialog with a WebView inside (Android)

查看:22
本文介绍了在 AlertDialog 中显示软键盘,其中包含 WebView (Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android 应用程序中,我创建了一个 AlertDialog,里面有一个 WebView.WebView 加载一个需要用户登录的网页.但是,当我点击WebView 中的文本字段时,软键盘没有出现.我一般都知道这个问题(Android:问题 7189);但是,就我而言,建议的解决方案似乎不起作用,因为我使用的是外部网站,而不仅仅是简单的 HTML 表单.

In my Android app I create an AlertDialog that has a WebView inside. The WebView loads a webpage that requires the user to log in. However, when I click on text fields in the WebView, soft keyboard does not appear. I am aware of the issue in general (Android: Issue 7189); however, in my case the suggested solution does not seem to work since I use an external website, and not just a simple HTML form.

完美的解决方案是当用户点击网站的文本字段时出现键盘.但是,让键盘与AlertDialog 一起出现也可以.有什么想法吗?

The perfect solution would be if the keyboard appeared when the user clicked on the website's text fields. However, having the keyboard appear together with theAlertDialog would also work. Any ideas?

推荐答案

看来最好的解决方案是简单地创建一个自定义对话框.自定义对话框似乎根本没有软键盘错误(它恰好在必须时显示).这是一些基本代码:

It seems that the best solution is to simply create a custom dialog. Custom dialogs do not appear to have the soft keyboard bug at all (it shows up exactly when it has to). Here's some basic code:

Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("My great title");
dialog.setCancelable(true);

dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);

WebView vw = (WebView) dialog.findViewById(R.id.wv);

这篇关于在 AlertDialog 中显示软键盘,其中包含 WebView (Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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