How to add “Go Back” function in WebView inside Fragment?

前端 未结 13 2037
余生分开走
余生分开走 2020-11-27 05:21

UPDATE: Solved! Problem was related to my Viewpager not WebView.

I\'m trying to add a \"Go Back\" function to my WebView which is insid

相关标签:
13条回答
  • 2020-11-27 05:45

    my solution was in fragment I added to public methods

    public static boolean canGoBack(){
            return mWebView.canGoBack();
        }
    
        public static void goBack(){
            mWebView.goBack();
        }
    

    then from activity I call

    @Override
    public void onBackPressed() {
        if(webFragment.canGoBack()){
            webFragment.goBack();
        }else{
            super.onBackPressed();
        }
    
    }
    

    note The mwebview is static

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