@SuppressLint("NewApi")
public class MainActivity extends Activity {
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.webv);
// 设置javascript生效
initSetting();
// 需要
loadass();
}
private void initSetting() {
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true); //设置javascript生效
//解析编码格式
webSettings.setDefaultTextEncodingName("gbk");// 设置编码格式
webSettings.setUseWideViewPort(true); //把图片全部显示
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不
//不让调用系统浏览,调用webView浏览器进行显示
wv.setWebViewClient(new WebViewClient(){
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
});
//让html中写js弹框 alert(); alter:修改列
wv.setWebChromeClient(new WebChromeClient(){
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
}
});
}
//
public void loadass() {
wv.loadUrl("file:///android_asset/test11.html");
// wv.loadUrl("www.baid.com"); //加载网址
}
public void load1() {
wv.loadData(
"<html><body><p style='color:red'> hello my name is gaoyn</p> </body> </html>",
"text/html", "gbk");
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && wv.canGoBack()) {
wv.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
public class MainActivity extends Activity {
private WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.webv);
// 设置javascript生效
initSetting();
// 需要
loadass();
}
private void initSetting() {
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true); //设置javascript生效
//解析编码格式
webSettings.setDefaultTextEncodingName("gbk");// 设置编码格式
webSettings.setUseWideViewPort(true); //把图片全部显示
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不
//不让调用系统浏览,调用webView浏览器进行显示
wv.setWebViewClient(new WebViewClient(){
@Override
public void onLoadResource(WebView view, String url) {
super.onLoadResource(view, url);
}
});
//让html中写js弹框 alert(); alter:修改列
wv.setWebChromeClient(new WebChromeClient(){
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
}
});
}
//
public void loadass() {
wv.loadUrl("file:///android_asset/test11.html");
// wv.loadUrl("www.baid.com"); //加载网址
}
public void load1() {
wv.loadData(
"<html><body><p style='color:red'> hello my name is gaoyn</p> </body> </html>",
"text/html", "gbk");
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && wv.canGoBack()) {
wv.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}