zoukankan      html  css  js  c++  java
  • Android之WebViewClient与WebChromeClient的区别

    ANDROID应用开发的时候可能会用到WEBVIEW这个组件,使用过程中可能会接触到WEBVIEWCLIENT与WEBCHROMECLIENT,那么这两个类到底有什么不同呢?
    WebViewClient主要帮助WebView处理各种通知、请求事件的,比如:

    onLoadResource
    onPageStart
    onPageFinish
    onReceiveError
    onReceivedHttpAuthRequest
    WebChromeClient主要辅助WebView处理Javascript的对话框、网站图标、网站title、加载进度等比如

    onCloseWindow(关闭WebView)
    onCreateWindow()
    onJsAlert (WebView上alert无效,需要定制WebChromeClient处理弹出)
    onJsPrompt
    onJsConfirm
    onProgressChanged
    onReceivedIcon
    onReceivedTitle
    看上去他们有很多不同,实际使用的话,如果你的WebView只是用来处理一些html的页面内容,只用WebViewClient就行了,如果需要更丰富的处理效果,比如JS、进度条等,就要用到WebChromeClient。
    更多的时候,你可以这样


    WebView webView;
    webView= (WebView) findViewById(R.id.webview);
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    这样你的WebView理论上就能有大部分需要实现的特色了
    当然,有些更精彩的内容还是需要你自己添加的

  • 相关阅读:
    linux下创建一个指定大小的文件
    批量替换多个文件中的字符串
    redhat 搭建yum 源
    python ConfigParser 模块
    python yaml 模块
    python xml文件处理
    py2exe 和pyinstaller打包
    wxpython 学习之 --threading
    wxpython 学习之 --文本框与Boxsizer布局管理器
    wxpython 学习之 --窗口分割
  • 原文地址:https://www.cnblogs.com/tfy1332/p/3654310.html
Copyright © 2011-2022 走看看