且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在android中禁用为webview按下的后退按钮?

更新时间:2022-12-19 16:08:44

如果您想在 WebView 可见时禁用后退按钮动作并在 WebView 可见时启用后退按钮动作> 在不可见 在您的活动中尝试以下代码

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