Android WebView Knowledge Accumulation

Source: Internet
Author: User

1. If there is JavaScript on the page visited, the WebView must be set to support JavaScript.

Mwebview.getsettings (). Setjavascriptenabled (True);

2, if the link in the page, if you want to click on the link to continue in the current browser response, instead of the new Android system browser should link in the ring, you must overwrite the WebView Webviewclient object.

Mwebview.setwebviewclient (New Webviewclient () {public Boolean shouldoverrideurlloading (WebView view, String URL) {         view.loadurl (URL);         return true; Returns True, representing the event has been processed, the event flows to this termination    }});

3, if do not do any processing, browse the Web page, click the System "back" button, the entire browser will call finish () and end itself, if you want to browse the page fallback instead of exiting the browser, 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.ca Ngoback ()) {                   mwebview.goback ();                          return true;               }               Return Super.onkeydown (KeyCode, event);           }

4. If the user is required to manually enter a user name, password, or other webview, the WebView must be set to support the get gesture focus.

Mwebview.requestfocusfromtouch ();

5. Rewrite the webchromeclient onprogresschanged method to update the progress bar.

Mwebview.setwebchromeclient (New Webchromeclient () {            //Update window Progress @Override public void when WebView progress changes            Onprogresschanged (WebView view, int newprogress) {                //activity has a progress range of 0 to 10000, so multiply                this LoadActivity.this.setProgress (newprogress *);            });

6, make webview support click Download link to jump.

        Mwebview.setdownloadlistener (New Downloadlistener ()        {            @Override public            void Ondownloadstart (String URL , string useragent, String contentdisposition, String mimetype, long ContentLength)            {                //TODO auto-generated Me Thod stub                uri uri = uri.parse (URL);                Intent Intent = new Intent (Intent.action_view, URI);                StartActivity (intent);            }        });

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.