package com.bwie.test.wzq_0818day15;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class SecondActivity extends AppCompatActivity {
private WebView wb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
wb = (WebView) findViewById(R.id.web);
WebSettings webSettings = wb.getSettings();
//设置可以访问文件
webSettings.setAllowFileAccess(true);
//设置支持缩放
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(true);
//设置Web视图
wb.setWebViewClient(new webViewClient ());
//加载数据
wb.loadUrl("https://www.baidu.com/");
}
@Override
//设置回退
//覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && wb.canGoBack()) {
wb.goBack(); //goBack()表示返回WebView的上一页面
return true;
}
finish();//结束退出程序
return false;
}
//Web视图
private class webViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}