【安卓-自定义布局】安卓App开发思路 一步一个脚印(十)实现内嵌在app中的webview 腾讯开源X5 高效安全

实现内嵌在app中的webview 采用腾讯开源X5 高效安全


webview在app的使用中,十分频繁,原生的webview加载速度相对来说很慢,而且很费流量。腾讯开源了x5的webview jar包,无疑是好事,毕竟经过了过亿的用户量的使用,性能还是值得赞的。

譬如咱们来加载百度页面




官方的网址为:

腾讯x5  http://x5.tencent.com/doc?id=1004

调用

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>




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值