Prior to WebView's understanding is very superficial, this time just study:
When loading URLs in WebView, use Load.url (""), but remember to configure them in Androidmanifest.xml. The configuration statement is: <uses-permission android:name= "Android.permission.INTERNET"/>
Overloaded shouldoverrideurlloading (WebView view, String URL), when linked at the time, is loaded in the software instead of jumping to the browser.
Processing of the return key: After we have opened multiple pages, we click Return to return to the previous page, but in fact it will close the current activity, so we have to handle the return key.
@Override
Public boolean onKeyDown (int keycode, keyevent event) {
if (KeyCode = = Keyevent.keycode_back && webview.cangoback ()) {
Webview.goback ();
return true;
} Else
return Super. OnKeyDown (KeyCode, event);
}
Page Forward button.
if (Webview.cangoforward ()) {
Webview.goforward ();
}Else{
Toast ("It's the last page, no more Forward");
}
When you click the Refresh button, execute webview.reload ();
If you want to add a message when the page loads, you can make a WebClient
Onpagestarted (WebView view, String URL, Bitmap favicon) {
}
Onpagefinished (WebView view, String URL) {}
Example:
@Override
public void Onpagestarted (WebView view, String URL, Bitmap favicon) {
& nbsp; if (Progdlg = = NULL | |!progdlg.isshowing ()) {
Progdlg = new ProgressDialog (CTX);
progdlg.setmessage ("Loading, please wait ... ");
}
progdlg.show ();
}
@Override
public void onpagefinished (WebView view, String URL) {
Progdlg.dismiss ();
}
7. If you want to know the loading progress, you need to call another class webchromeclient.
Example:
Webview.setwebchromeclient (New Webchromeclient () {
@Override
public void onprogresschanged (WebView view, int newprogress) {
Message msg = new Message ();
Msg.what = 200;
Msg.obj = newprogress;
Handler.sendmessage (msg);
}
}
Then update the progress bar in the 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
}
};
};