[英]Show soft keyboard in AlertDialog with a WebView inside (Android)
在我的Android应用程序中,我创建了一个AlertDialog
WebView
的AlertDialog
。 WebView
加载需要用户登录的网页。但是,当我单击WebView
文本字段时,不会出现软键盘。 我一般都知道这个问题( Android:Issue 7189 ); 但是,在我的情况下,建议的解决方案似乎不起作用,因为我使用外部网站,而不仅仅是一个简单的HTML表单。
如果用户点击网站的文本字段时出现键盘,那么完美的解决方案就是。 但是,让键盘与AlertDialog
一起显示也可以。 有任何想法吗?
似乎最好的解决方案是简单地创建一个自定义对话框。 自定义对话框似乎根本没有软键盘错误(它完全显示在必要时)。 这是一些基本代码:
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类。
public static class LocalWebView extends WebView { public LocalWebView(Context context) { super(context); } public LocalWebView(Context context, AttributeSet attrs) { super(context, attrs); } public LocalWebView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public LocalWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public LocalWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) { super(context, attrs, defStyleAttr, privateBrowsing); } @Override public boolean onCheckIsTextEditor() { return true; } }
在您将AlertDialog设置为内容视图的布局中使用此LocalWebView而不是原始WebView。
如果它仍然相关,对我来说问题与沉浸式对话+ webview有关。
我通过在对话框窗口设置一个标志 - NOT FOCUS来覆盖对话框show方法来实现身临其境,一旦我删除了它,我就失去了沉浸感但现在我的网页对话框弹出了键盘......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.