您现在的位置是:首页 > 文章详情

webView 显示一段 html 代码

日期:2017-05-15点击:399
 

1、布局文件

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context=".MainActivity"> <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent"> </WebView> </RelativeLayout>

 

2、代码

package com.webview.demo; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.webkit.WebView; public class MainActivity extends AppCompatActivity { private WebView webView ; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String webs = "\"<table style='font-size:12px;'><tr><td style='width:45px;'>" + "起&nbsp;&nbsp;&nbsp;&nbsp;日:</td><td>当日22:00前投资," + "当日计息</td></tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;日:</td><td>每日7点</td></tr><tr><td>还款方式:" + "</td><td>按日付息</td></tr></table>\"" ; webView = (WebView) findViewById( R.id.webview ); //webview webView.loadDataWithBaseURL( null, webs , "text/html", "UTF-8", null ) ; } }

 

3、显示效果

原文链接:https://yq.aliyun.com/articles/304014
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章