老套路看图:
这是通过webview加载HTML源码显示的网页:加载方法如下:
webview.loadDataWithBaseURL(null, htmlData, "text/html", "utf-8", null);
设置滚动条不显示的方法有两种:
第一种:在xml中配置scrollbars为none即可
<WebView
android:id="@+id/wv_read_msg_content"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="10dp"
android:scrollbars="none" />
第二种:Java代码设置
//设置WebView滚动条不显示
//水平不显示
wvReadMsgContent.setHorizontalScrollBarEnabled(false);
//垂直不显示
wvReadMsgContent.setVerticalScrollBarEnabled(false);
设置webview自适应的方法:
//设置网页自适应
wvReadMsgContent.getSettings().setUseWideViewPort(true);
wvReadMsgContent.getSettings().setLoadWithOverviewMode(true);
设置webview支持手势缩放功能
// 设置可以支持缩放
wvReadMsgContent.getSettings().setSupportZoom(true);
// 设置出现缩放工具
wvReadMsgContent.getSettings().setBuiltInZoomControls(true);
设置后再看下效果:
WebView已自适应,WebView滚动条也隐藏了HTML数据也加载出来了
如果看着复杂我贴下完整代码:xml(缺少的资源文件请自行补全)
activity_read_message.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="wrap_content"