webView 显示一段 html 代码
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;'>" + "起 息 日:</td><td>当日22:00前投资," + "当日计息</td></tr><tr><td>还 款 日:</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、显示效果
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
AppCompatActivity实现全屏的问题
前言:我的 Activity 是继承 BaseActivity , 而 BaseActivity 继承AppCompatActivity 。 BaseActivity 的继承 /** * 应用程序的基类 * */ public class BaseActivity extends AppCompatActivity { } HomeActivity 的继承 public class HomeActivity extends BaseActivity{ } 一:错误的发生 报错信息 二:正确的代码思路 在 styles里面新建一个 style <!-- Activity全屏 开始--> <style name="MyFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">true&...
- 下一篇
Android 显示 WebView ,加载URL 时,向webview的 header 里面传递参数
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、代码实现 1 package com.webvi...
相关文章
文章评论
共有0条评论来说两句吧...