WebView "Instance resolution" for Android network programming

Source: Internet
Author: User

WebView

Role:
A Web page can be displayed as a view (essentially a Web page) on the phone's client side.

Mainactivity code "Instance resolution"


Package Com.example.webview;import Android.os.bundle;import Android.app.activity;import android.view.KeyEvent; Import Android.view.menu;import Android.view.window;import Android.webkit.webview;import Android.webkit.webviewclient;public class Mainactivity extends Activity {private WebView WebView; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Requestwindowfeature (window.feature_ No_title); Setcontentview (r.layout.activity_main); WebView = (WebView) This.findviewbyid (R.id.webview); Webview.getsettings (). Setjavascriptenabled (true);//is support for JavaScript language Webview.loadurl ("https://www.baidu.com/"); Webview.setwebviewclient (New Mywebviewclient ());} /* * Remove the progress bar and URL from the Web page shown in WebView to make it more like a customer service application * * */class Mywebviewclient extends webviewclient{@Overridepublic boolean Shouldov Errideurlloading (WebView view, String URL) {view.loadurl (URL); return true;}} /** * Make the Click rewind button not exit the entire application directly but return to the previous page * */@Overridepublic boolean onKeyDown (int keycode, keyevent event) {if (keycode= = Keyevent.keycode_back&&webview.cangoback ()) {webview.goback ();//Return to last page return true;} Return Super.onkeydown (KeyCode, event);//exit the entire application}}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

WebView "Instance resolution" for Android network programming

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.