Android Web browser Development detailed (a)

Source: Internet
Author: User

Android Web browser Development detailed (a)


Please support the original, respect for the original, reproduced please indicate the source: Http://blog.csdn.net/kangweijian (from Kangweijian of the csdn blog)

Android Web Browser Developer Development detailed ( i ) , mainly through WebView The class implements five functions such as loading a webpage, refreshing the page, loading the history page forward, loading the history page backwards, and zooming in on the page.

Android Web Browser Developer Development detailed ( two ) , the main implementation of bookmarks and history of saving, deletion, editing and other functions.

Android Web Browser Developer Development detailed ( three ) , mainly through Asynctask class implements the ability to access multiple Web sites in one click.

1、 WebView

a)     WebView是个用来显示网页的视图类。这个类基于你可以滚动你的网页浏览器或者简单的显示一些在线内容在你的Activity。它使用WebKit渲染引擎去实现:载入网页、向前载入历史网页和向后载入历史网页,缩放网页以及执行文字搜索等功能。

b)    使用WebView自定义属于自己的网页浏览器

I. modifying WebView 的内部类 WebSettings ,通过 getsettings () 得到 WebSettings Here's how we use this class:

1. setJavaScriptEnabled() method Enable JavaScript.

2. setBuiltInZoomControls(boolean) You can enable WebView the built-in zoom feature. Note: If the height and width of the component is set to the WRAP_CONTENT scale function is not valid.

3. Setusewideviewport (TRUE); Set any scale scaling. After zooming, for the content to fit the screen, do not exceed the off-screen display, implement line wrapping. This effect should be controlled by HTML rather than WebView. For example <pstyle= "Word-break:break-all" >test</p> implement line wrapping.

4.     addJavascriptInterface(Object, String)method to inject Java objects into the WebView so that the Web page can be accessed through JavaScript . Of course, this is also risky, because some of the possible problem pages can be directly in touch with the application.

II. 创建和设置 WebChromeClient 子类。当一些可能会影响浏览器 UI 的事情发生时 WebChromeClient 类会被调用。例如:进度条更新和 JavaScript warnings are sent. Here are some of the ways we use this class:

1.shouldoverrideurlloading(WebView View,String URL). When there's a newURLloaded intoWebView (For example, click on a link), the method determines the next decision. such as returntrue, meaning "don't deal with thisURL, I'll do it myself. " such as returnfalse, meaning that "WebViewto load thisURLand I'm not going to do anything about it. "

                iii.          Create and set webviewclient subclass. webviewclient class is called when something that affects content rendering occurs. For example, error or report submission. You can interrupt the loading of the URL here. Here's how we use this class:

1.      onprogresschanged ( webview &NBSP; view, intnewprogress) Span style= "color: #222222; Background: #F7F7F7 ">. This method tells us to load the current page of the Progress program. newprogress The value in 0 to 100

2.      onreceivedtitle ( webview &NBSP; VIEW,&NBSP; string &NBSP; title)

c) WebView 默认不提供像浏览器那样的组件、默认不支持 JavaScript and Ignore network errors. In addition to reading Web pages, users cannot interact with the Web page in other things. If you want a complete and mature Web browser, you can invoke the browser app:

URI Uri =uri.parse ("http://www.baidu.com") intentintent = new Intent (Intent.action_view, URI); StartActivity (Intent);  

2. Add the necessary permissions (Androidmanifest.xml)

a) <uses-permissionandroid:name="Android.permission.INTERNET" />

 

Please support the original, respect for the original, reproduced please indicate the source: Http://blog.csdn.net/kangweijian (from Kangweijian of the csdn blog)

Learn about the authoritative guide to Android programming and notes BY2015.2.20 Morning

Android Web browser Development detailed (a)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.