如何显示HTML内容的使用android的web视图视图、内容、HTML、web

2023-09-04 03:04:32 作者:浅唱丶悲伤

下面是我想使用Android SDK中的web视图,以显示我的HTML内容。它只会显示

  

//请

但是,当我把这个HTML内容到浏览器上,它显示了不同的。

 < BR />< BR />阅读讲义请明天< BR />< BR /><! - 作业帮助功课


帮助辅导孩子做功课的家庭作业小学中学初中



//  - ><字体颜色=#60c000大小=4><强>请< / STRONG>< / FONT>!
 

请建议如何解决此问题

我还有一个问题,在HTML内容有一个标签

 < IMG SRC =htt​​p://www.homeworknow.com/hwnow/upload/images/tn_star300.gif边界=0/>
 

在此图像不显示。

解决方案 使用web.loadDataWithBaseURL代替web.loadData(不要忘了逃跑的地方的需要字符串) 您需要添加Internet权限下载图片,并查看他们在您的清单文件。 android

本示例为我的作品:

 公共类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,编码,);
    }

}
 

不要忘了加一句:

 <使用-权限的Andr​​oid:名称=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