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.