Teach you to create your first Android app with Android Studio load HTML5 page (ii)

Source: Internet
Author: User

After the previous article, we can already open the HTML page, but there are many details of the content we need to adjust.

    • problems opening a link

Careful netizen may have found, open Baidu page, click the link at the top, will open the corresponding page in the browser of the phone, this is obviously not what we want.

Add the following code in the OnCreate

Webview.setwebviewclient (New Webviewclient ()
{
public boolean shouldoverrideurlloading (WebView view,string URL)
{
View.loadurl (URL);
return true;
}
});

You can open the link on the current page.

    • Fallback Issues

The problem of opening the link is resolved, but after the link is opened, click the Back button to exit the program directly.

Overloads the onkeydown function so that it is rolled back within the page

@Override

@Override
public boolean onKeyDown (int keycoder,keyevent event)
{
In-page fallback
if ((keycoder==keyevent.keycode_back) && webview.cangoback ()) {
Webview.goback ();
return true;
}

Return Super.onkeydown (keycoder,event);
}

Questions that pop up in the prompt box

Add a button to the index page, alert pop-up prompt

<button onclick= "alert (' Test popup ')" > Pop-up Window </button>

Teach you to create your first Android app with Android Studio load HTML5 page (ii)

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.