N
N
Nikita Timofeev2017-03-01 17:42:09
Java
Nikita Timofeev, 2017-03-01 17:42:09

How to make back button in webview?

When I press the back button, the application closes, how can I make it go back to the previous page?

package test.test;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class MainActivity extends Activity {

    WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView) findViewById(R.id.webview);

        webView.getSettings().setJavaScriptEnabled(true);

        webView.loadUrl("http://");
        webView.setWebViewClient(new WebViewClient() {
                                     @Override
                                     public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                                         return super.shouldOverrideUrlLoading(view, request);
                                     }
                                 }

        );
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2017-03-01
@jons_2

public void onBackPressed(){
    if (webView.canGoBack()) {
         webView.goBack()
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question