android第一行代码笔记15-webview

2020-07-02  本文已影响0人  刚刚8888
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <WebView
            android:id="@+id/web_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

...

public class MainActivity extends Activity {
        private WebView webView;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            webView = (WebView) findViewById(R.id.web_view);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.setWebViewClient(new WebViewClient() {
url) {
系统浏览器
@Override
public boolean shouldOverrideUrlLoading(WebView view, String
view.loadUrl(url); // 根据传入的参数再去加载新的网页
return true; // 表示当前WebView可以处理打开新网页的请求,不用借助
} });
            webView.loadUrl("http://www.baidu.com");
        }
}

...
// 权限配置
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.webviewtest"
        android:versionCode="1"
        android:versionName="1.0" >
......
        <uses-permission android:name="android.permission.INTERNET" />
......
</manifest>
上一篇 下一篇

猜你喜欢

热点阅读