优势就不多说了,文档里面写的很清除,但是没有找到demo,不知道为什么,网络上找了一些东西记下来
接入文档:https://x5.tencent.com/tbs/guide/sdkInit.html
1、在application里面加载sdk
private void initTbs() { //搜集本地tbs内核信息并上报服务器,服务器返回结果决定使用哪个内核。 QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() { @Override public void onViewInitFinished(boolean arg0) { LogUtil.i("View是否初始化完成:" + arg0); } @Override public void onCoreInitFinished() { LogUtil.i("X5内核初始化完成"); } }; QbSdk.setTbsListener(new TbsListener() { @Override public void onDownloadFinish(int i) { LogUtil.i("腾讯X5内核 下载结束"); } @Override public void onInstallFinish(int i) { LogUtil.i("腾讯X5内核 安装完成"); } @Override public void onDownloadProgress(int i) { LogUtil.i("腾讯X5内核 下载进度:%" + i); } }); QbSdk.initX5Environment(getApplicationContext(), cb); }2、在你的activity里面
webView = findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true);
private void loadUrl(String url) { webView.loadUrl(url); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onReceivedError(WebView var1, int var2, String var3, String var4) { progressBar.setVisibility(View.GONE); ToastUtil.showShort(SwipActivity.this, "网页加载失败"); } }); //进度条 webView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { if (newProgress == 100) { progressBar.setVisibility(View.GONE); return; } progressBar.setVisibility(View.VISIBLE); progressBar.setProgress(newProgress); } }); } @Override protected void onDestroy() { super.onDestroy(); if (webView != null) webView.destroy(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) { webView.goBack(); return true; } return super.onKeyDown(keyCode, event); }就这么多,简单明了
当然里面还有好多注意事项,建议仔细查看文档