How to control the Android WebView history/back stack?

后端 未结 7 1976
半阙折子戏
半阙折子戏 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 10:58

    this snippet work for me, try it:

    @Override
    public void onBackPressed() {
        BlankFragment fragment = (BlankFragment)
                getSupportFragmentManager().findFragmentByTag("webView");
        if (fragment.canGoBack()) {
            fragment.goBack();
        } else {
            super.onBackPressed();
        }
      }
    

提交回复
热议问题