1.首先在res下新建activity的UI文件
2.对应的界面逻辑代码
package com.game.test;import android.app.Activity;import android.webkit.WebResourceRequest;import android.webkit.WebSettings;import android.webkit.WebViewClient;import android.widget.Button;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.webkit.WebView;import android.widget.ImageButton;public class WebViewActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web_view_layer); WebView webView = (WebView) findViewById(R.id.webView); String url = "http://www.csdn.net"; webView.loadUrl(url); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true);// 支持JavaScript webSettings.setSupportZoom(true);// 支持缩放 webSettings.setBuiltInZoomControls(true); // 如果不设置WebViewClient 那么会调用系统的浏览器 webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { // AndroidStudio 提示Override方法快捷键 Alt+Insert return super.shouldOverrideUrlLoading(view, request); } }); // 关闭网页按钮 Button btn = (Button) findViewById(R.id.button); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); ImageButton imageButton = (ImageButton) findViewById(R.id.imgBtn); imageButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); }}
3.AndroidManifest.xml修改
增加这个activity
增加网络访问的权限