M
M
Maxim2021-07-18 00:07:16
Android
Maxim, 2021-07-18 00:07:16

Webview why back button not working?

tell me what is the problem, the back button in the application does not work

public class Tab1 extends Fragment {
 
    public WebView mWebView;
 
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v=inflater.inflate(R.layout.tab1, container, false);
        mWebView = (WebView) v.findViewById(R.id.webViewT1);
        mWebView.loadUrl("file:///android_asset/Maps/web/map.html");
        mWebView.getSettings().setBuiltInZoomControls(true);
        mWebView.getSettings().setDisplayZoomControls(false);
 
 
        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
 
        // Force links and redirects to open in the WebView instead of in a browser
        mWebView.setWebViewClient(new WebViewClient());
 
        return v;
    }
    public void onBackPressed(){
        if (mWebView.canGoBack()) {
            mWebView.goBack();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2021-07-18
@402d

if you added the Override directive, you would immediately notice that the fragment does not have a .
It's at the activation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question