How to go back to previous page if back button is pressed in WebView?

后端 未结 17 1223
迷失自我
迷失自我 2020-11-22 07:06

I have an app in which I have a WebView where I display some websites. It works, clicking a link in the webpage goes to the next page in the website inside my a

17条回答
  •  情书的邮戳
    2020-11-22 07:41

    Focusing should also be checked in onBackPressed

        @Override
        public void onBackPressed() {
            if (mWebview.isFocused() && mWebview.canGoBack()) {
                mWebview.goBack();       
            } else {
                super.onBackPressed();
                finish();
            }
        }
    

提交回复
热议问题