Android将HTML文本显示在webView控件中
16lz
2021-01-23
1.简单明了,直接上代码
public class LiveBBCCAgreementActivity extends BaseActivity implements LiveBBCCAgreeContract.LiveBBCCAgreeView { private LinearLayout titleBar; private WebView BBCCWebview; private String URL; private LiveBBCCAgreeContract.LiveBBCCAgreePresenter liveBBCCAgreePresenter; @Override protected int setContentLayout() { return R.layout.live_activity_agreement; } @Override protected void init() { initTitleBar(titleBar, "协议", false, null); BBCCWebview = (WebView) findViewById(R.id.BBCC_webview); liveBBCCAgreePresenter = new LiveBBCCAgreePresenterImpl(this); liveBBCCAgreePresenter.getLiveBBCCAgree(); WebSettings webSettings = BBCCWebview.getSettings(); /*与js交互*/ webSettings.setJavaScriptEnabled(true); /*自适应屏幕*/ webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小 webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 /*细节操作*/ webSettings.setBuiltInZoomControls(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持js弹窗 BBCCWebview.setWebViewClient(new WebViewClient()); } @Override protected void findView() { titleBar = (LinearLayout) findViewById(R.id.title_bar_2); } @Override protected void initData() { } @Override protected void setListeners() { } @Override public void onClick(View v) { } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TODO: add setContentView(...) invocation ButterKnife.bind(this); } @Override public void showLiveBBCCAgree(LiveBBCCAgreeBean liveBBCCAgreeBean) { URL = ""+liveBBCCAgreeBean.getData().getContent()+""; /** * 将文本HTML显示在webview中 */ BBCCWebview.loadDataWithBaseURL(null,URL,"text/html","utf-8",null); }}2.XML
<?xml version="1.0" encoding="utf-8"?>xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> android:id="@+id/title_bar_2" layout="@layout/title_bar" /> android:id="@+id/BBCC_webview" android:layout_width="match_parent" android:layout_height="match_parent" />
更多相关文章
- android屏幕解锁
- Android屏幕投影及反向控制原理
- android 面试题 谈谈屏幕适配
- android缩放大图片加载
- [Android] 一种粗暴快速的 Android 全屏幕适配方案
- android自定义adapter 滑动屏幕时 进度条显示混乱