Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to add "Go Back" function in WebView inside Fragment?
    primarykey
    data
    text
    <p><strong>UPDATE: Solved! Problem was related to my Viewpager not WebView.</strong></p> <p>I'm trying to add a "Go Back" function to my <code>WebView</code> which is inside a <code>Fragment</code>. But I can't figure out how to:</p> <pre><code>public final class TestFragment extends Fragment { static WebView mWeb; private View mContentView; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContentView = inflater.inflate(R.layout.webview, null); mWeb = (WebView)mContentView.findViewById(R.id.webview); WebSettings settings = mWeb.getSettings(); settings.setJavaScriptEnabled(true); settings.setSupportZoom(false); mWeb.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); mWeb.getSettings().setBuiltInZoomControls(false); mWeb.loadUrl("myurl..."); mWeb.setOnKeyListener(new OnKeyListener(){ public boolean onKey(View v, int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) &amp;&amp; mWeb.canGoBack()) { mWeb.goBack(); return true; } return false; } }); } } </code></pre> <p>I also tried something like:</p> <pre><code>@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) &amp;&amp; mWeb.canGoBack()) { mWeb.goBack(); return true; } return super.onKeyDown(keyCode, event); } </code></pre> <p>Another solution but same problem:</p> <pre><code>@Override public void onBackPressed() { if(webView.canGoBack()) webView.goBack(); else super.onBackPressed(); } </code></pre> <p>Any ideas how to get this working?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload