106 lines
3.6 KiB
Java
106 lines
3.6 KiB
Java
package com.sl.house_property;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.view.View;
|
|
import android.webkit.WebChromeClient;
|
|
import android.webkit.WebSettings;
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebViewClient;
|
|
import android.widget.ImageView;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
|
|
public class WebActivitytwo extends AppCompatActivity implements View.OnClickListener {
|
|
public final static String URL = "url";
|
|
public final static String TITLE = "title";
|
|
private WebView webView;
|
|
private ProgressBar pb;
|
|
private RelativeLayout mLayTopLeftTv;
|
|
private TextView mLayTopTitle;
|
|
private TextView mRight;
|
|
private ImageView mIvCode;
|
|
private ProgressBar mPb;
|
|
private WebView mWebView;
|
|
|
|
public static void runActivity(Context context, String title, String url) {
|
|
Intent intent = new Intent(context, WebActivitytwo.class);
|
|
intent.putExtra(URL, url);
|
|
intent.putExtra(TITLE, title);
|
|
context.startActivity(intent);
|
|
}
|
|
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_webtwo);
|
|
String url = getIntent().getStringExtra(URL);
|
|
String title = getIntent().getStringExtra(TITLE);
|
|
|
|
initView();
|
|
pb.setMax(100);
|
|
|
|
WebSettings webSettings = webView.getSettings();
|
|
webSettings.setDomStorageEnabled(true);//主要是这句
|
|
webSettings.setJavaScriptEnabled(true);//启用js
|
|
webSettings.setBlockNetworkImage(false);//解决图片不显示
|
|
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
webSettings.setLoadsImagesAutomatically(true);
|
|
webSettings.setAppCacheEnabled(true);
|
|
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
|
// webView.getSettings().setJavaScriptEnabled(true);
|
|
webSettings.setSupportZoom(true);
|
|
webSettings.setBuiltInZoomControls(true);
|
|
webView.setWebChromeClient(new WebChromeClient() {
|
|
@Override
|
|
public void onProgressChanged(WebView view, int newProgress) {
|
|
pb.setProgress(newProgress);
|
|
if (newProgress >= 100) {
|
|
pb.setVisibility(View.GONE);
|
|
}
|
|
}
|
|
});
|
|
|
|
webView.setWebViewClient(new WebViewClient() {
|
|
@Override
|
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
view.loadUrl(url);
|
|
return true;
|
|
}
|
|
});
|
|
webView.loadUrl(url);
|
|
|
|
}
|
|
|
|
private void initView() {
|
|
webView = (WebView) findViewById(R.id.webView);
|
|
webView.setOnClickListener(this);
|
|
pb = (ProgressBar) findViewById(R.id.pb);
|
|
mLayTopLeftTv = (RelativeLayout) findViewById(R.id.layTop_left_tv);
|
|
mLayTopLeftTv.setOnClickListener(this);
|
|
mLayTopTitle = (TextView) findViewById(R.id.layTop_title);
|
|
mRight = (TextView) findViewById(R.id.right);
|
|
mIvCode = (ImageView) findViewById(R.id.iv_code);
|
|
mPb = (ProgressBar) findViewById(R.id.pb);
|
|
mWebView = (WebView) findViewById(R.id.webView);
|
|
mLayTopTitle.setText("智慧豆豆");
|
|
}
|
|
|
|
@Override
|
|
public void onClick(View v) {
|
|
switch (v.getId()) {
|
|
default:
|
|
break;
|
|
case R.id.webView:
|
|
break;
|
|
case R.id.layTop_left_tv:
|
|
finish();
|
|
break;
|
|
}
|
|
}
|
|
}
|