WebView interacts with HTML, gets click events, and processes response logic

Source: Internet
Author: User

First look at the following figure:



What we now see is a loaded HTML webview, our current requirement is to press the return arrow in the upper left corner to exit the app;

This requires Java code to interact with HTML, so how do you implement it?

At first, I read a lot of information on the Internet, but it doesn't work in me.

Finally, I think of the solution, is this:

Webview.setwebviewclient (New Mywebview ());

The Mywebview here is my custom, the specific code is as follows:

    public class Mywebview extends Webviewclient {public

        void onpagefinished (webview view, String URL) {
            super.onpag efinished (view, URL);

        public boolean shouldoverrideurlloading (webview view, String URL) {

            log.e ("goldactivity", "WebView url" +url);

            if (Url.contains ("Backtoappindex")) {
                GoldActivity.this.finish ();
            }
            Return super.shouldoverrideurlloading (view, URL);
        }
    
shouldoverrideurlloading (webview view,string URL)

This aspect actually is in WebView inside clicks the event to call, inside has two parameters, in which URL is you clicks the time which sends the URL
Here is what you can get, and then you have to check with your front end, click on the URL of the return button, and then you can judge here, if consistent, the code logic you want to execute.

And then it's done.

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.