赞
踩
webview在app的使用中,十分频繁,原生的webview加载速度相对来说很慢,而且很费流量。腾讯开源了x5的webview jar包,无疑是好事,毕竟经过了过亿的用户量的使用,性能还是值得赞的。
譬如咱们来加载百度页面
private WebView X5WebView;//使用腾讯X5WebView
private String url = "http://wap.baidu.com";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view_test);
X5WebView = (com.tencent.smtt.sdk.WebView)findViewById(R.id.tbsContent);
X5WebView.loadUrl(url);
WebSettings webSettings = X5WebView.getSettings();
webSettings.setJavaScriptEnabled(true);
X5WebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && X5WebView.canGoBack()) {
X5WebView.goBack();// 返回前一个页面
return true;
}
return super.onKeyDown(keyCode, event);
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <com.tencent.smtt.sdk.WebView android:id="@+id/tbsContent" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。