【问题标题】:HTML string to webview [closed]HTML字符串到webview [关闭]
【发布时间】:2015-01-01 12:59:48
【问题描述】:

我想创建一个安卓应用,

apk 可能有一个文本框和一个按钮。

用户将在文本框中输入他们的 HTML 代码/字符串。 通过单击按钮,它将显示他们从文本框中键入的代码的输出。

【问题讨论】:

    标签: android html webview


    【解决方案1】:

    你可以这样做

    public class MainActivity 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>
    

    【讨论】:

      【解决方案2】:

      拨打此行:

      wv.loadData(yourHtmlData, "text/html", "UTF-8");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-04
        • 1970-01-01
        相关资源
        最近更新 更多