webview最全面详解(一)了解官方文档

更多信息请阅读用WebView构建 Web应用程序

Basic usage


By default, a WebView provides no browser-like widgets, does not enable JavaScript and web page errors are ignored. If your goal is only to display some HTML as a part of your UI, this is probably fine; the user won’t need to interact with the web page beyond reading it, and the web page won’t need to interact with the user. If you actually want a full-blown web browser, then you probably want to invoke the Browser application with a URL Intent rather than show it with a WebView. For example:

默认情况下,webview并不提供类似浏览器的不见,不支持JavaScript 并且忽略网页错误。如果你的目的是仅仅显示一些HTML作为你的UI的一部分,那可能不错,用户阅读网页而不需要与之交互,网页也不需要和用户交互。

如果你真的想要一个完整的Web浏览器,那你可能需要通过一个URL intent调用浏览器应用程序而不是在WebView中显示它,

例如:

Uri uri = Uri.parse(“https://www.example.com”);

Intent intent = new Intent(Intent.ACTION_VIEW, uri);

startActivity(intent);

See Intent for more information.

To provide a WebView in your own Activity, include a in your layout, or set the entire Activity window as a WebView during onCreate():

请参阅意图获取更多信息。

要在你的activity中支持webview,需要在layout中添加标签,或者在 onCreate()方法中将整个activity窗口设置为一个webview。

WebView webview = new WebView(this);

setContentView(webview);

Then load the desired web page:

然后加载所需网页

// Simplest usage: note that an exception will NOT be thrown

// if there is an error loading this page (see below).

// 最简单的应用:注意在这种情况下,如果在加载的页面出现错

// 误,这个异常不会被抛出(如下)

webview.loadUrl(“https://example.com/”);

// OR, you can also load from an HTML string:

//而或,你也可以加载HTML字符串

String summary = “You scored 192 points.”;

webview.loadData(summary, “text/html”, null);

// … although note that there are restrictions on what this HTML can do.

// See loadData(String, String, String) and loadDataWithBaseURL(String, String, String, String, String) for more info.

// Also see loadData(String, String, String) for information on encoding special characters.

当然,要注意的是加载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 WebViewClien

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值