When some browsing web pages are displayed on mobile terminals, they can be packaged and made into Android APP, so as to implement a simple APP function for specific people.
The specific implementation method is as follows:Copy the code
The first step:
The most important thing to do is to grant network permissions to your APP and add to the resource file:Copy the code
<uses-permission android:name="android.permission.INTERNET"/>
Copy the code
The second step:
Edit the interface in the layout resource file to achieve specific functions.
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Copy the code
Step 3:
In the main program directly write call Web access code, and achieve the function of returning to the superior page.
// define
webView =findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(
true);
//The url to load is webview.loadurl ("http://vrdytt.com");
webView.setWebViewClient(new WebViewClient() {
// Override the shouldOverrideUrlLoading() method to open a web page in this WebView instead of calling the system browser
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
// When each page is loaded, the action can get the current page information such as URL, such as title, etc.});
// Monitor the back button to ensure that the previous page @override can be rolled back
public boolean onKeyDown(int keyCode, KeyEvent event){
if((keyCode == KEYCODE_BACK) && webView.canGoBack()){
webView.goBack();
return true;
}
return super.onKeyDown(keyCode,event);
}
// Release resources to prevent overflow @override
protected void onDestroy(a) {
super.onDestroy();
// Release resources
webView.destroy();
webView=
null;
}
```javaCopy the code