How to disable back button pressed for webview in android ?
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (wv1 != null && (keyCode == KeyEvent.KEYCODE_BACK)
&& wv1.canGoBack() )
{
wv1.goBack();
}
return true;
}
If you want to disable back button action when the WebView
Visible and enable back button action if the WebView
in not Visible try the below code in your Activity
@Override
public void onBackPressed() {
if(webview.getVisibility()==View.VISIBLE){
// dont pass back button action
if(webview.canGoBack()){
webview.goBack();
}
return;
}else{
// pass back button action
super.onBackPressed();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With