[英]WebView not loading URL in Dialog
我正在嘗試顯示一個顯示Webview的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();
但是什么也沒發生。 看來網頁視圖沒有大小
我被要求提供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>
我建議看這里: android:對話框或彈出窗口中的webview
而是使用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 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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.