簡體   English   中英

Webview從文件中加載圖像但不在Android中從Web加載圖像

[英]Webview load images from file but not from web in android

您好,我想將HTML數據加載到WiebView中。 我的html數據包含兩個圖像,一個位於資產文件夾中,另一個位於Web上。 我的代碼是這樣的:

String html  = "<html><body><img src="image1.jpg"><img src="http://www.example.com/images/image2.jpg"></body></html>";

webView = (WebView) rootView.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);

webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8",null);

但是Web視圖僅加載第一張圖像,而不會加載Web圖像。 誰能幫助我解決問題?

您的代碼還可以(除了未轉義的引號外),但您可能忘記了請求Webview的Internet Permitinon。 將此添加到清單文件中:

<uses-permission android:name="android.permission.INTERNET" />

首先在清單中添加互聯網許可。 第二寫:

webView.loadDataWithBaseURL("http:///android_asset/", html, "text/html", "UTF-8",null);

不:

webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8",null);

因為http顯示網絡,文件顯示內部存儲器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM