注:如不雅应用的是Post请求方法,则此办法不会被回调
2、shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
3、shouldInterceptRequest(WebView view, String url)
在API 21今后过时,通知Application加载资本的请求并返回请求的资本,如不雅返回值是Null,Webview仍然会按正常加载资本;不然返回的数据将会被应用。
注:回调产生在子线程中,不克不及直接进行UI操作
4、shouldInterceptRequest(WebView view, WebResourceRequest request)
在API 21今后新加,应用同上。
5、onPageStarted(WebView view, String url, Bitmap favicon)
通知Application页面已经开端加载资本,页面加载过程中,onPageStarted至多会被履行一次。
1、经由过程XML初始化:
通知Application页面已经加载完毕。
7、onReceivedError(WebView view, int errorCode, String description, String failingUrl)
通知Application出缺点产生,这些缺点是弗成恢复的(即重要的资本弗采取)。errorCode参数对应于一个ERROR_ *常量
- webView.addJavascriptInterface(new WebAppInterface(this), "android");
WebCromeClient
1、onProgressChanged(WebView view, int newProgress)
通知Application的加载进度,newProgress取值范围[0,100],可以经由过程这个办法来编写一个带加载进度条的Webview,具编制子请参考:Android 编写一个带进度条的Webview
2、onReceivedTitle(WebView view, String title)
控制Webview加载汗青网页
WebView重写URL加载时,它会主动累积的汗青拜访的web页面。可以经由过程向后goBack()和向前goForward()。
举例,可以在Activity中的回退键控制向后回退到前一个页面:
在API 24今后新加的,应用同上。
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- // Check if the key event was the Back button and if there's history
- if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
- webview.goBack();
- return true;
- } // If it wasn't the Back key or there's no web page history, bubble up to the default
- // system behavior (probably exit the activity)
- return super.onKeyDown(keyCode, event);
- }
Webview和Js交互
1、Js调用Android接口:
- public class WebAppInterface {
- Context mContext;
- /** Instantiate the interface and set the context */
推荐阅读
【技巧沙龙】AI开辟者拭魅战营-7分钟打造1个定制技能。7月22号,我们等你一路! 国度卫计委长途医疗治理与培训中间办公室主任卢清君(中国台湾网 尹赛楠 摄)2017年(第九届>>>详细阅读
本文标题:Android Webview使用和遇到过的坑总结
地址:http://www.17bianji.com/lsqh/36219.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示