简体   繁体   中英

Creating an Browser like back button in Webview android

I have an back button(Image Button) on the webview. I want to make this back button work like browser back button. Whenever the user clicks on the back button it should move to the previous web page. Looking forward to your reply. thanks.

Implement an OnClickListener for that ImageButton and inside onClick() write something like this:

if(mWebView.canGoBack()){
     mWebView.goBack();
}else{
     finish();
}

See WebView guide from Android

Use One image button

create the onClick event of that button

insite the onClick Button you have to write

webview.goBack();

this code will work as back button of browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM