Android WebView示例教程

Android WebView is used to display HTML in an android app. We can use android WebView to load HTML page into android app.

Android WebView用于在Android应用程序中显示HTML。 我们可以使用android WebView将HTML页面加载到android应用中。

Android WebView (Android WebView)

Android WebView component is a full-fledged browser implemented as a View subclass to embed it into our android application.

Android WebView组件是成熟的浏览器,实现为View子类,可将其嵌入到我们的android应用程序中。

Android WebView的重要性 (Importance Of Android WebView)

For HTML code that is limited in terms of scope, we can implement the static method fromHtml() that belongs to the HTML Utility class for parsing HTML-formatted string and displaying it in a TextView.

对于受范围限制HTML代码,我们可以实现属于HTML Utility类的静态方法fromHtml() ,用于解析HTML格式的字符串并将其显示在TextView

TextView can render simple formatting like styles (bold, italic, etc.), font faces (serif, sans serif, etc.), colors, links, and so forth.

TextView可以呈现简单的格式,如样式(粗体,斜体等),字体(衬线,无衬线等),颜色,链接等。

However, when it comes to complex formatting and larger scope in terms of HTML, then TextView fails to handle it well. For example browsing Facebook won’t be possible through a TextView.

但是,当涉及到复杂的格式和更大HTML范围时,TextView无法很好地处理它。 例如,将无法通过TextView浏览Facebook。

In such cases, WebView will be the more appropriate widget, as it can handle a much wider range of HTML tags. WebView can also handle CSS and JavaScript, which Html.fromHtml() would simply ignore.

在这种情况下, WebView将是更合适的小部件,因为它可以处理范围更广HTML标签。 WebView还可以处理CSS和JavaScript,而Html.fromHtml()只会忽略它们。

WebView can also assist with common browsing metaphors, such as history list of visited URLs to support backwards and forwards navigation.

WebView还可以协助常见的浏览隐喻,例如已访问URL的历史列表,以支持向后和向前导航。

Still WebView comes with its own set of cons such as it’s a much more expensive widget to use, in terms of memory consumption than a TextView. The reason for this increased memory is because WebView is powered by WebKit/Blink that are open source Web rendering engine to power content in browsers like Chrome.

WebView仍然具有自己的缺点,例如,在内存消耗方面,它比TextView使用起来要昂贵得多。 内存增加的原因是因为WebView由WebKit / Blink提供支持,它们是开放源Web渲染引擎,可为诸如Chrome之类的浏览器提供内容。

Android WebView示例 (Android WebView Example)

Android WebView component is inserted into the XML layout file for the layout we want the WebView to be displayed in. In this example we insert it into the activity_main.xml file as shown below:

将Android WebView组件插入到XML布局文件中,以用于我们希望在其中显示WebView的布局。在此示例中,我们将其插入到activity_main.xml文件中,如下所示:

<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    androi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值