public class MainActivity extends AppCompatActivity implements View.OnClickListener { String TAG = "主活动"; Button startWebview; WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); startWebview = (Button) findViewById(R.id.start_webview); webView = (WebView) findViewById(R.id.webview); startWebview.setOnClickListener(this); } @Override public void onClick(View v) { int id = v.getId(); if(id == R.id.start_webview){ Log.d(TAG,"onClick");
// 通过该语句让网页在当前页面显示 webView.setWebViewClient(new WebViewClient()); webView.loadUrl("http://www.baidu.com"); } } }