如何显示HTML内容的使用android的web视图 [英] how to show the html contents to the webview using android
本文介绍了如何显示HTML内容的使用android的web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我想使用Android SDK中的web视图,以显示我的HTML内容。它只会显示
//请
但是,当我把这个HTML内容到浏览器上,它显示了不同的。
< BR />< BR />阅读讲义请明天< BR />< BR /><! - 作业帮助功课
帮助辅导孩子做功课的家庭作业小学中学初中
// - ><字体颜色=#60c000大小=4><强>请< / STRONG>< / FONT>!
请建议如何解决此问题
我还有一个问题,在HTML内容有一个标签
< IMG SRC =http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif边界=0/>
在此图像不显示。
解决方案
- 使用web.loadDataWithBaseURL代替web.loadData(不要忘了逃跑的地方的需要字符串)
- 您需要添加Internet权限下载图片,并查看他们在您的清单文件。
本示例为我的作品:
公共类SimpleMusicStream延伸活动{
@覆盖
公共无效的onCreate(包冰柱){
super.onCreate(冰柱);
的setContentView(R.layout.main);
的WebView WV =(web视图)findViewById(R.id.WebView01);
最后弦乐MIMETYPE =text / html的;
最终的字符串编码=UTF-8;
字符串的HTML =< BR />< BR />阅读讲义请明天< BR />< BR /><! - 作业辅导功课+
帮帮忙做作业家庭作业小学中学初中+
// - >!<字体颜色='#60c000大小=4><强>请< / STRONG>< / FONT>中+
&所述; IMG SRC ='的http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif'/>中;
wv.loadDataWithBaseURL(,HTML,MIMETYPE,编码,);
}
}
不要忘了加一句:
<使用-权限的Android:名称=android.permission.INTERNET对>< /使用-许可>
在AndroidManifest.xml文件
Following is my html content which i want to show in the webview using android sdk. It will displays only
//Please
But when I put this HTML content into the browser then it shows differently.
<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>
Please suggest how to resolve this problem
I have another problem that in HTML content there is a tag
<img src="http://www.homeworknow.com/hwnow/upload/images/tn_star300.gif" border="0" />
in this images does not shows.
解决方案
- Use web.loadDataWithBaseURL instead of web.loadData (And don't forget to escape strings where it's needed)
- You need to add internet permission to download images and view them in your manifest file.
This example works for me:
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, "");
}
}
And don't forget to add:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
in your AndroidManifest.xml file
这篇关于如何显示HTML内容的使用android的web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文