项目需要内嵌浏览器,连接到公司的网站联系我们。使用WebView.使用方法如下:
一、先在XML布局文件中,写好WebView.如:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <WebView android:id="@+id/contactUsWW" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
//设置WebView属性,能够执行Javascript脚本 webView.getSettings().setJavaScriptEnabled(true); //加载需要显示的网页 webView.loadUrl(webUrl); //设置Web视图 webView.setWebViewClient(new HelloWebViewClient ());
//Web视图 private class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } }
<uses-permission android:name="android.permission.INTERNET" />
原文:http://blog.csdn.net/howlaa/article/details/19488297