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