我写了一个在对话框中打开webView的函数, 问题是当我点击textArea时键盘没有弹出 我尝试了this线程中的所有解决方案无济于事
此代码在android.support.v4.app.Fragment
中起作用 public void openWebView() {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this.getActivity());
WebView webView = new WebView(this.getActivity());
webView.loadUrl("http://www.google.com");
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
alertBuilder.setView(webView);
webView.getSettings().setJavaScriptEnabled(true);
alertBuilder.show();
}
当我按下文本区域几次时,这是日志:
09-15 11:44:56.165 27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::nextTextOrSelectNode : nextNode is NULL
09-15 11:44:56.165 27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::previousTextOrSelectNode : !previousNode )
09-15 11:45:04.715 27483-27542/ngapps.socialbackground D/webview﹕ blockWebkitViewMessage= false
09-15 11:45:04.720 27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::nextTextOrSelectNode : nextNode is NULL
09-15 11:45:04.720 27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::previousTextOrSelectNode : !previousNode )
09-15 11:45:04.720 27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::nextTextOrSelectNode : nextNode is NULL
09-15 11:45:04.720 27483-27542/ngapps.socialbackground D/webcoreglue﹕ WebViewCore::previousTextOrSelectNode : !previousNode )
答案 0 :(得分:2)
您可以像这样定义假键盘:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
WebView wv = new WebView(this);
LinearLayout wrapper = new LinearLayout(this);
EditText keyboardHack = new EditText(this);
keyboardHack.setVisibility(View.GONE);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl(loadUrl);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
wrapper.setOrientation(LinearLayout.VERTICAL);
wrapper.addView(wv, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
wrapper.addView(keyboardHack, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
alert.setView(wrapper);