Android手机中内置了一款高性能webkit内核,该内核完美封装到了WebView组件中,而从js中直接调用java方法和在java中直接调用js方法更是让我们看到了WebView的强大,下面这个小例子介绍了怎样在js和java中双向调用方法 1.首先是布局文件main.xml Xml代码   

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:andro); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent);   

api中为我们提供了一个通过webView加载页面的例子,

我们可以看到,主要有loadUrl()和loadData()方法。这里请注意各个参数的含义哦、
-------------------------------------------------------------
此外,android还为我们提供了一些类来辅助我们的webview的使用。
WebViewClient:
。WebViewClient就是帮助WebView处理各种通知、请求事件的,具体来说包括:
 
  onLoadResource:通知webView加载url指定的资源时触发
  onPageStart:页面开始加载时触发
  onPageFinish:页面加载完毕时触发
  onReceiveError:出现错误时触发
  WebChromeClient:
WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等
   onCloseWindow(关闭WebView)
  onCreateWindow()
  onJsAlert (WebView上alert是弹不出来东西的,需要定制你的WebChromeClient处理弹出)
  onJsPrompt
  onJsConfirm
  onProgressChanged
  onReceivedIcon
  onReceivedTitle
api中提供给我们一个实例:

WebSetting:和WebView是一一绑定的,控制webview的一些基础设置信息,如是否识别javascript,网页是否可放大缩小等。
--------------------------------------------------------------------------
如果我们想通过webview进行历史网页查看时,一定要注意,先通过如下方法判断下是否可执行该操作才好:

然后就可通过
voidgoBack()
Go back in the history of this WebView.
voidgoBackOrForward(int steps)
Go to the history item that is the number of steps away from the current item.
voidgoForward()
Go forward in the history of this WebView.
三个方法进行操作了,其中goBackOrForward传递进负数时为back操作,正数为forward操作。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-12
  • 2022-12-23
  • 2021-12-03
  • 2021-08-13
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案