【发布时间】:2015-08-12 18:07:56
【问题描述】:
我正在尝试制作一个显示 web 视图的 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.setWebChromeClient(new WebChromeClient());
String customHtml = "<html><body>WebViewTest</body></html>";
webView.loadData(customHtml, "text/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>
【问题讨论】:
-
发布用于 webview 的布局。
-
试试这个
webView.loadData(customHtml, "text/html; charset=UTF-8", null);