Mobile website to Android app

Source: Internet
Author: User

Today is to help friends check whether in the app can point outside the chain of a test, do to feel, the test was optimized. Okay, let's get down to the chase.

Tools: Android Studio

First step: Create a new project

Step two: Drag in the control (WebView)

Step three: Write the background method

1. Add the following code to the OnCreate:

        WebView loading Web page        final WebView WebView = (WebView) Findviewbyid (R.id.webview);        Webview.getsettings (). Setjavascriptenabled (true);        Webview.loadurl ("http://www.luoruiyuan.cn");        Webview.setwebviewclient (New Examplewebviewclient ());        Click the Back button to have WebView back one page (or overwrite the activity's OnKeyDown method)        Webview.setonkeylistener (new View.onkeylistener () {            @ Override Public            Boolean OnKey (View v, int keycode, keyevent event) {                if (event.getaction () = = Keyevent.action_dow N) {                    if (keycode = = Keyevent.keycode_back && webview.cangoback ()) {  //= Action                        When the return key is pressed Webview.goback ();   Back                        //webview.goforward ();//forward                        return true;    Processed                    }                }                return false;}        );

2. Modify Internet access

Code:

<uses-permission android:name= "Android.permission.INTERNET"/><uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "/>
Fourth step: Modify the app icon and name

Final effect:

Mobile website to Android app

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.