无法在Web视图中加载html

时间:2015-04-16 08:11:04

标签: android html android-webview

在我的应用程序中,我想在Web视图中显示一个html数据。我试过了,但是html数据没有显示在webview中。请帮我解决

代码

webView = (WebView) view.findViewById(R.id.webView);



        if (!strSendTo.equals("")) {
            etSendTo.setText(strSendTo);
        }

        if (!htmlData.equals("")) {

            webView.loadData(htmlData, MIME_TYPE, ENCODING);
        }

HTML

<HTML>

<HEAD>
  <TITLE></TITLE>
</HEAD>

<BODY>
  <TABLE border=0 cellSpacing=0 cellPadding=10 background=#FFFFFF align=center>
    <TBODY>
      <TR>
        <TD vAlign=top>
          <TABLE style=MARGIN-TOP: 40px border=0 cellSpacing=0 cellPadding=0 width=709 align=center>
            <TBODY>
              <TR>
                <TD>&nbsp;</TD>
              </TR>
              <TR>
                <TD>
                  <P>
                    <STRONG>Hello Jadya ,</STRONG>
                  </P>
                  <P>Please check your expenses of trip 'Goa' dated from 14/04/2015 to 23/04/2015.</P>
                </TD>
              </TR>
              <TR>
                <TD height=15></TD>
              </TR>
              <TR>
                <TD>
                  <TABLE border=1 cellSpacing=0 cellPadding=5>
                    <TBODY>
                      <TR>
                        <TD height=30 colSpan=6 align=middle>
                          <STRONG>Credit / Contribution </STRONG>
                        </TD>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Category</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>
                          <STRONG>Amount</STRONG>
                        </TD>
                      </TR>
                      <TR>
                        <TD noWrap align=left>Contribution</TD>
                        <TD noWrap align=right>1000.00</TD>
                      </TR>
                      <TR>
                        <TD noWrap align=left>Expenses</TD>
                        <TD noWrap align=right>0.00</TD>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Total</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>
                          <STRONG>1000.00</STRONG>
                        </TD>
                      </TR>
                    </TBODY>
                  </TABLE>
                </TD>
              </TR>
              <TR>
                <TD height=15></TD>
              </TR>
              <TR>
                <TD height=8>
                  <TABLE border=1 cellSpacing=0 cellPadding=5>
                    <TBODY>
                      <TR>
                        <TD height=30 colSpan=6 align=middle>
                          <STRONG>Payable Amount</STRONG>
                        </TD>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Category</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>
                          <STRONG>Amount</STRONG>
                        </TD>
                      </TR>
                      <TR>
                        <TD noWrap align=left>Drink</TD>
                        <TD noWrap align=right>40.00</TD>
                      </TR>
                      <TR>
                        <TD noWrap align=left>Entertainment</TD>
                        <TD noWrap align=right>200.00</TD>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Total</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>
                          <STRONG>240.00</STRONG>
                        </TD>
                      </TR>
                    </TBODY>
                  </TABLE>
                </TD>
              </TR>
              <TR>
                <TD height=15></TD>
              </TR>
              <TR>
                <TD height=8> </TD>
              </TR>
              <TR>
                <TD style=BACKGROUND-REPEAT: repeat-x ; HEIGHT: 2px; BACKGROUND-POSITION: center 140px; background=></TD>
              </TR>
              <TR>
                <TD height=8>
                  <TABLE border=0 cellSpacing=0 cellPadding=5>
                    <TBODY>
                      <TR>
                        <TD height=30 colSpan=6 align=left>
                          <h3><u>Net Balance</u></h3></TD>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Credit / Contribution</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>1000.00</TD>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Payable</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>-240.00</TD>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Amount Received From</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>-0.00</TD>
                      </TR>
                      <TR>
                        <TD colspan=2>
                          <HR size=1> </td>
                      </TR>
                      <TR>
                        <TD width=140 noWrap align=left>
                          <STRONG>Net Balance</STRONG>
                        </TD>
                        <TD width=120 noWrap align=right>
                          <STRONG>760.00</STRONG>
                        </TD>
                      </TR>
                    </TBODY>
                  </TABLE>
                </TD>
              </TR>
              <TR>
                <TD style=BACKGROUND-REPEAT: repeat-x ; HEIGHT: 2px; BACKGROUND-POSITION: center 140px; background=></TD>
              </TR>
              <TR>
                <TD height=8></TD>
              </TR>
              <TR>
                <TD height=8></TD>
              </TR>
              <TR>
                <TD height=8 width=709></TD>
              </TR>
              <TR>
                <TD style=BACKGROUND-REPEAT: repeat-x; BACKGROUND-POSITION: center 140px; background=></TD>
              </TR>
              <TR>
                <TD height=8></TD>
              </TR>
              <TR>
                <TD height=8></TD>
              </TR>
            </TBODY>
          </TABLE>
        </TD>
      </TR>
    </TBODY>
  </TABLE>
</BODY>

</HTML>

1 个答案:

答案 0 :(得分:0)

从WebView Class官方页面:

http://developer.android.com/reference/android/webkit/WebView.html

String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html", null);

以及为什么你的Html标签是大写的?