Android WebView未在对话框中加载URL
我正在尝试制作一个显示网络视图的Android对话框:Android WebView未在对话框中加载URL,android,webview,dialog,Android,Webview,Dialog,我正在尝试制作一个显示网络视图的Android对话框: final Dialog dialog = new Dialog(mActivity); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.layout); WebView webView = (WebView)dialog.findViewById(R.id.webview); webView.setWebChromeC
final Dialog dialog = new Dialog(mActivity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.layout);
WebView webView = (WebView)dialog.findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());
String customHtml = "<html><body>WebViewTest</body></html>";
webView.loadData(customHtml, "text/html", "UTF-8");
dialog.show();
final Dialog=新建对话框(mActivity);
对话框.requestWindowFeature(窗口.FEATURE\u无\u标题);
setContentView(R.layout.layout);
WebView WebView=(WebView)dialog.findviewbyd(R.id.WebView);
setWebChromeClient(新的WebChromeClient());
字符串customHtml=“WebViewTest”;
加载数据(自定义html、“文本/html”、“UTF-8”);
dialog.show();
但什么都没有发生。webview似乎没有大小
我被要求提供xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="300dp"
android:padding="10sp"
android:background="#0ff"
android:orientation="vertical">
<WebView
android:background="#f0f"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
我建议看这里: 与其使用AlertDialog,它将更好地满足您的需求:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Title here");
WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
alert.setView(wv);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.show();
final Dialog=新建对话框(mActivity);
对话框.requestWindowFeature(窗口.FEATURE\u无\u标题);
setContentView(R.layout.layout);
WebView WebView=(WebView)dialog.findviewbyd(R.id.WebView);
setWebChromeClient(新的WebChromeClient());
字符串customHtml=“WebViewTest”;
loadData(customHtml,“text/html;charset=UTF-8”,null);
dialog.show();
发布用于webview的布局。尝试此webview.loadData(customHtml,“text/html;charset=UTF-8”,null)
@JackFinch,如果这个答案对你有帮助,那么勾选绿色标记,而不是简单地说“谢谢”,这样对未来的用户也有帮助。
final Dialog dialog = new Dialog(mActivity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.layout);
WebView webView = (WebView)dialog.findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());
String customHtml = "<html><body>WebViewTest</body></html>";
webView.loadData(customHtml, "text/html; charset=UTF-8", null);
dialog.show();