How to control the Android WebView history/back stack?

后端 未结 7 1974
半阙折子戏
半阙折子戏 2021-02-04 10:49

I am trying to figure out a way to handle the WebView back stack similar to how the Android web browser handles it when the back button is pressed from within my own app\'s WebV

相关标签:
7条回答
  • 2021-02-04 11:06

    your onKeyDown should look like these

    @Override
       public boolean onKeyDown(int keyCode, KeyEvent event)
      {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
            myWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
       }
    

    here myWebView is declared in the Activity's onCreate

    0 讨论(0)
提交回复
热议问题