瀏覽代碼

Enable going back in history with backpress on Android if history is available; otherwise, destroy the webview activity. The user is still able to immediately leave the webview with the button present on the top left corner.

Mohammed Al Sahaf 8 年之前
父節點
當前提交
30b269d5e5
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      android/src/main/java/com/flutter_webview_plugin/WebviewActivity.java

+ 4 - 0
android/src/main/java/com/flutter_webview_plugin/WebviewActivity.java

@@ -76,6 +76,10 @@ public class WebviewActivity extends Activity {
 
     @Override
     public void onBackPressed() {
+        if(webView.canGoBack()){
+            webView.goBack();
+            return;
+        }
         FlutterWebviewPlugin.channel.invokeMethod("onBackPressed", null);
         super.onBackPressed();
     }