【问题标题】:Android html image probAndroid html图像问题
【发布时间】:2011-07-01 07:22:56
【问题描述】:

我正在使用loadData() 在 web 视图中显示一个包含 html 代码的文本文件。 html 代码有一个像 <img src="file:///android_asset/test.png" alt="cd4+ cell"> 这样的图像标签,并将 test.png 文件放在 res\drawable 文件夹中。但是没有 img 的 webview 显示完美。我的系统中的问题在哪里?

【问题讨论】:

    标签: html image android-webview loaddata


    【解决方案1】:

    尝试使用loadDataWithBaseUrl() 而不是loadData()。像这样的:

    public void loadHTML() {  
        final String mimeType = "text/html";  
        final String encoding = "utf-8";  
        final String html = "<img src=\"file:///android_asset/test.png\" />";  
    
        WebView wv = (WebView) findViewById(yourIDhere);  
        wv.loadDataWithBaseURL("fake://not/needed", html, mimeType, encoding, ""); 
    }
    

    【讨论】:

    • 它不仅仅是一个短的 html...它是一个长的 html 文件...我正在从文件中读取它并通过 loadData() 显示它。此 html 包含图像。
    【解决方案2】:

    你可以看到 CDATA 或者在上面的代码中你可以添加你的标签

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      相关资源
      最近更新 更多