public class MainActivity extends Activity { WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webView = (WebView)findViewById(R.id.webview); // js可用 webView.getSettings().setJavaScriptEnabled(true); // 在当前webview中打开,不在浏览器中打开连接 webView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { webView.loadUrl(request.getUrl().toString()); return true; } }); webView.loadUrl("http://www.baidu.com"); } }
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
时间: 2024-10-03 04:57:53