以下是我要在webview中使用android sdk显示的html内容。它只会显示
//请
但是当我将这个HTML内容放入浏览器时,它会以不同的方式显示。
<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework
help help with homework homework assignments elementary school high school middle school
// --><font color="#60c000" size="4"><strong>Please!</strong></font>
请建议如何解决此问题
我还有一个问题,就是在HTML内容中有一个标签
<img src="http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif" border="0" />
在此图片中没有显示。
答案 0 :(得分:57)
此示例适用于我:
public class SimpleMusicStream extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.WebView01);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = "<br /><br />Read the handouts please for tomorrow.<br /><br /><!--homework help homework" +
"help help with homework homework assignments elementary school high school middle school" +
"// --><font color='#60c000' size='4'><strong>Please!</strong></font>" +
"<img src='http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif' />";
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
}
不要忘记添加:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
在AndroidManifest.xml文件中
答案 1 :(得分:7)
您可以按上述方式执行此操作,也可以将html文件放入资产文件夹中,然后使用它来显示它
view.loadUrl("file:///android_asset/FILENAME.html");
答案 2 :(得分:0)
用于图像显示,您可以像
那样进行String str= " img src=\"http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif\" alt=\"this is img\"ALIGN=\"right\"/>"; wv.loadData(str, "text/html", "utf-8");