How to disable back button pressed for webview in android?

前端 未结 6 781
时光说笑
时光说笑 2020-12-19 15:38

How to disable back button pressed for webview in android ?

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
     if (wv1 != null &&         


        
6条回答
  •  旧巷少年郎
    2020-12-19 16:18

    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();
       }
    }
    

提交回复
热议问题