package com.sl.house_property; import android.graphics.Color; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ProgressBar; import com.sl.house_property.databinding.ActivityAboutusBinding; public class AboutusActivity extends BaseActivity { private ProgressBar progressBar; @Override protected int getLayoutResId() { return R.layout.activity_aboutus; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // String url="https://wy.shiningsoft.top/articlemobile/index/detail?article_id=3"; String url="https://wy.dou1.net/articlemobile/index/detail?article_id=3"; // String url="https://wy.dou1.net/articlemobile/index/detail?article_id=1"; String titile=getIntent().getStringExtra("titile"); setAbr("关于我们", new View.OnClickListener() { @Override public void onClick(View view) { finish(); } },0,null,0,null,0,null,""); // progressDialog=new ProgressDialog(NewsDetailActivity.this); setWebView(url); } private void setWebView(String data) { WebView webview = mDataBinding.fullscreenContent1; progressBar=mDataBinding.progressBar2; webview.setBackgroundColor(Color.WHITE); // webview.loadDataWithBaseURL(null, data, "text/html" , "utf-8", null); // webview.loadData(data,"text/html" ,"utf-8"); webview.loadUrl(data); WebSettings webSettings = webview.getSettings(); //如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript webSettings.setJavaScriptEnabled(true); //设置自适应屏幕,两者合用 webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小 webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 //缩放操作 webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。 webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放 webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件 //其他细节操作 webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存 webSettings.setAllowFileAccess(true); //设置可以访问文件 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口 webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片 webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式 webSettings.setAppCachePath(getPackageCodePath()+"/myapp"); webSettings.setAppCacheMaxSize(10000); //webview.loadUrl("www.baidu.com"); webview.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return super.shouldOverrideUrlLoading(view, url); } }); webview.setWebChromeClient(new WebChromeClient(){ @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress < 100) { progressBar.setProgress(newProgress); } else { progressBar.setVisibility(View.GONE); } } }); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if( mDataBinding.fullscreenContent1.canGoBack()){ mDataBinding.fullscreenContent1.goBack(); } else finish(); return true; } return super.onKeyDown(keyCode, event); } }