Example usage for android.webkit WebView goBack

List of usage examples for android.webkit WebView goBack

Introduction

In this page you can find the example usage for android.webkit WebView goBack.

Prototype

public void goBack() 

Source Link

Document

Goes back in the history of this WebView.

Usage

From source file:com.purchasingpower.inappbrowser.WebViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //setContentView(R.layout.activity_main);
    setContentView(getResources().getIdentifier("nativebrowserplugin", "layout", getPackageName()));
    if (!checkPermission()) {
        requestPermission();//  ww w .j a va2s. c  om
    }
    Intent intent = getIntent();
    String url = intent.getExtras().getString("url");
    final WebView myWebView = (WebView) findViewById(
            getResources().getIdentifier("webview", "id", getPackageName()));
    myWebView.setWebViewClient(new MyWebViewClient());

    webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setAllowFileAccess(true);
    myWebView.setWebChromeClient(new PQChromeClient());
    //if SDK version is greater of 19 then activate hardware acceleration otherwise activate software acceleration
    if (Build.VERSION.SDK_INT >= 19) {
        myWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    } else if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 19) {
        myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    myWebView.loadUrl(url);

    back = (ImageView) findViewById(getResources().getIdentifier("back", "id", getPackageName()));
    back.setImageResource(getResources().getIdentifier("back_gray", "drawable", getPackageName()));
    forward = (ImageView) findViewById(getResources().getIdentifier("forward", "id", getPackageName()));
    forward.setImageResource(getResources().getIdentifier("forward_gray", "drawable", getPackageName()));
    done = (TextView) findViewById(getResources().getIdentifier("done", "id", getPackageName()));
    pbar = (ProgressBar) findViewById(getResources().getIdentifier("pbar", "id", getPackageName()));
    pbar.setVisibility(View.VISIBLE);
    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (myWebView.canGoBack()) {
                myWebView.goBack();
            }
        }
    });
    forward.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (myWebView.canGoForward()) {
                myWebView.goForward();
            }
        }
    });
    done.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.v("Done", "Clicked");
            finish();
        }
    });
}