Share common items in webview
To load a page with webview, just webview. loadurl ("http://m.baidu.com"); of course don't forget to add network Permissions
Click the hyperlink in the webpage. multiple browsers will pop up, but to open it in our browser, we need to set webviewclient
webView.setWebViewClient(new WebViewClient(){}
Processing of the Return key: After opening multiple webpages, we click back to return to the previous webpage, but in fact the current activity will be closed, so we need to process the return key.
@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {webView.goBack();return true;} elsereturn super.onKeyDown(keyCode, event);}
Here is the difference between return true and return false.
When true is returned, it indicates that the event has been fully executed and no other callback functions are executed. If false is returned, it indicates that the event is not fully processed and other callback functions will be called.
I just talked about moving backwards. How can I proceed?
Run the following command when the forward button is clicked.
If (webview. cangoforward () {webview. goforward ();} else {toast ("this is the last page, so you cannot move on again ");}
Run the command when the refresh button is clicked.
webView.reload();
During page loading, we may need to give users a friendly prompt, which is also done in webviewclient ().
Webview. setwebviewclient (New webviewclient () {@ overridepublic void onpagestarted (webview view, string URL, bitmap favicon) {If (progdlg = NULL |! Progdlg. isshowing () {progdlg = new progressdiwing (CTX); progdlg. setmessage ("loading... ") ;}Progdlg. Show () ;}@ overridepublic void onpagefinished (webview view, string URL) {progdlg. Dismiss ();}}
To know the loading progress during page loading, you need to use another class webchromeclient.
webView.setWebChromeClient(new WebChromeClient(){@Overridepublic void onProgressChanged(WebView view, int newProgress) {Message msg = new Message(); msg.what = 200; msg.obj = newProgress; handler.sendMessage(msg);}}
Update the progress bar in Handler
private Handler handler = new Handler(){public void handleMessage(android.os.Message msg) {switch (msg.what) {case 200:int progress = (Integer) msg.obj;progressBar.setProgress(progress);break;default:break;}};};
After loading, let the progressbar disappear.