html - 如何使用android向webview显示html内容

标签 html android android-webview

以下是我想使用 android sdk 在 webview 中显示的 html 内容。它只会显示

//Please

但是当我把这个 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" />

在这张图片中没有显示。

最佳答案

  1. 使用 web.loadDataWithBaseURL 代替 web.loadData(别忘了在需要的地方转义字符串)
  2. 您需要添加互联网权限才能下载图像并在 list 文件中查看它们。

这个例子对我有用:

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 文件中

关于html - 如何使用android向webview显示html内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3624171/

相关文章:

php - 获取标签值php

JavaScript FORTNITE API 请求

android - 不需要在 Manifest 中注册 Activity 基类?

android - Google Play 服务位置和地理围栏 API 在 Genymotion 上无法正常工作

html - 如何使每个其他 div 具有不同的颜色

html - 下划线左浮动div

java - 在另一个类中调用包含textView和radio组的类

android - HTML5 视频移除叠加播放图标

android - Web View 不在 android 中显示 html 数据

android - ListView 与网页 View