Adds history go back for webview activity when back key is pressed

This commit is contained in:
tom79 2017-08-07 12:18:06 +02:00
parent 4b7cfa07f2
commit 218a874830
1 changed files with 11 additions and 2 deletions

View File

@ -52,7 +52,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads;
public class WebviewActivity extends AppCompatActivity {
private String url;
private WebView webView;
@Override
@ -74,7 +74,7 @@ public class WebviewActivity extends AppCompatActivity {
if( getSupportActionBar() != null)
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
WebView webView = Helper.initializeWebview(WebviewActivity.this, R.id.webview);
webView = Helper.initializeWebview(WebviewActivity.this, R.id.webview);
setTitle("");
FrameLayout webview_container = (FrameLayout) findViewById(R.id.webview_container);
@ -146,6 +146,15 @@ public class WebviewActivity extends AppCompatActivity {
this.url = newUrl;
}
@Override
public void onBackPressed() {
if (webView.canGoBack()){
webView.goBack();
} else {
super.onBackPressed();
}
}
@Override
public void onDestroy(){
super.onDestroy();