Webview Overview (custom basic behavior)

Source: Internet
Author: User

Original article: http://www.cnblogs.com/oakpip/archive/2011/04/08/2009800.html
WebKit is a software framework included in Mac OS X v10.3 and later versions (for v10.2.7 and later versions, you can also obtain it through software updates ). WebKit is also the foundation of Mac OS X's Safari web browser. WebKit is an open-source project. It is mainly modified by KDE's khtml and contains some components from Apple.
Traditionally, WebKit contains a web engine WebCore and a script engine javascriptcore, which correspond to KDE's khtml and KJS respectively. However, as Javascript Engines become more and more independent, WebKit and WebCore are now basically mixed (for example, Google Chrome and Maxthon 3 adopt V8 engines, but they still claim to be WebKit kernels ).
Here we will first try to use webview to browse Web pages in Android. There is a simple example of webview In SDK Dev guide.

Pay attention to the following points during development:
1. androidmanifest. xml must use the permission "android. Permission. Internet". Otherwise, the web page not available error may occur.
2. If the accessed page contains JavaScript, webview must be set to support JavaScript.
Webview. getsettings (). setjavascriptenabled (true );
3. If you want to click the link on the page to continue responding in the current browser, instead of making a response in the browser of the new Android system, you must overwrite the webviewclient object of webview.
Mwebview. setwebviewclient (New webviewclient (){
Public Boolean shouldoverrideurlloading (webview view, string URL ){
View. loadurl (URL );
Return true;
}
});

4. if you do not do any processing, browse the webpage and click the system "back" key. The entire activity will call finish () and end itself, if you want to roll back the web page instead of ending the activity of the current web page, you need to process and consume the back event in the current activity.

Public Boolean onkeydown (INT keycode, keyevent event ){
If (keycode = keyevent. keycode_back) & mwebview. cangoback ()){
Mwebview. Goback ();
Return true;
}
Return super. onkeydown (keycode, event );
}

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.