webview最全面详解(一)了解官方文档,androidndk开发

当然,要注意的是加载HTML是有限制的

请查阅loadData(String, String, String)和loadDataWithBaseURL(String, String, String, String, String)文档获取更多信息。

有关编码特殊字符的信息,另请参阅loadData(String,String,String)。

A WebView has several customization points where you can add your own behavior. These are:

Creating and setting a WebChromeClient subclass. This class is called when something that might impact a browser UI happens, for instance, progress updates and JavaScript alerts are sent here (see Debugging Tasks).

Creating and setting a WebViewClient subclass. It will be called when things happen that impact the rendering of the content, eg, errors or form submissions. You can also intercept URL loading here (via shouldOverrideUrlLoading()).

Modifying the WebSettings, such as enabling JavaScript with setJavaScriptEnabled().

Injecting Java objects into the WebView using the addJavascriptInterface(Object, String) method. This method allows you to inject Java objects into a page’s JavaScript context, so that they can be accessed by JavaScript in the page.

Here’s a more complicated example, showing error handling, settings, and progress notification:

webview有一些可以自定义的地方,你可以自定义自己的方法。这些分别是:

创建和设置一个WebChromeClient WebChromeClient 类。当某些可能影响浏览器用户界面的事件发生时会调用此类,例如,发送进度更新和JavaScript弹出alert的时候(请参阅调试任务)。

(译者注:WebChromeClient是辅助WebView处理Javascript的对话框,网站图标,网站title,加载进度等 )

创建和设置一个WebViewClient 类,当影响内容呈现的事情发生时,它会被调用,例如提交错误或表单。 你也可以在这里拦截URL加载(通过 shouldOverrideUrlLoading()]

(译者注:WebViewClient就是帮助WebView处理各种通知、请求事件的)

// Let’s display the progress in the activity title bar, like the

// browser app does.

//让我们像浏览器程序一样在activity标题栏展示加载进度

getWindow().requestFeature(Window.FEATURE_PROGRESS);

webview.getSettings().setJavaScriptEnabled(true);

final Activity activity = this;

webview.setWebChromeClient(new WebChromeClient() {

public void onProgressChanged(WebView view, int progress) {

// Activities and WebViews measure progress

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值