From 9407b271ed9a58ab0a5d536fc14dd6ffe892c190 Mon Sep 17 00:00:00 2001 From: Crizant Lai Date: Fri, 24 Jul 2020 13:00:32 +0800 Subject: [PATCH] [webview_flutter] add option to set the background to transparent --- .../io/flutter/plugins/webviewflutter/FlutterWebView.java | 3 ++- .../io/flutter/plugins/webviewflutter/InputAwareWebView.java | 5 ++++- packages/webview_flutter/example/lib/main.dart | 4 +++- packages/webview_flutter/ios/Classes/FlutterWebView.m | 5 +++++ packages/webview_flutter/lib/platform_interface.dart | 4 ++++ packages/webview_flutter/lib/src/webview_method_channel.dart | 1 + packages/webview_flutter/lib/webview_flutter.dart | 5 +++++ 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java index bfb79a39e8ba..074f12be33d0 100644 --- a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java +++ b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/FlutterWebView.java @@ -87,7 +87,8 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) { DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); displayListenerProxy.onPreWebViewInitialization(displayManager); - webView = new InputAwareWebView(context, containerView); + boolean opaque = (boolean) params.get("opaque"); + webView = new InputAwareWebView(context, containerView, opaque); displayListenerProxy.onPostWebViewInitialization(displayManager); platformThreadHandler = new Handler(context.getMainLooper()); diff --git a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java index 9b81a5b7cc6b..87023affb371 100644 --- a/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java +++ b/packages/webview_flutter/android/src/main/java/io/flutter/plugins/webviewflutter/InputAwareWebView.java @@ -31,9 +31,12 @@ final class InputAwareWebView extends WebView { private ThreadedInputConnectionProxyAdapterView proxyAdapterView; private View containerView; - InputAwareWebView(Context context, View containerView) { + InputAwareWebView(Context context, View containerView, boolean opaque) { super(context); this.containerView = containerView; + if (!opaque) { + setBackgroundColor(0x00000000); + } } void setContainerView(View containerView) { diff --git a/packages/webview_flutter/example/lib/main.dart b/packages/webview_flutter/example/lib/main.dart index 7ec3008337d8..5cd50c028504 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -17,7 +17,7 @@ const String kNavigationExamplePage = ''' Navigation Delegate Example

-The navigation delegate is set to block navigation to the youtube website. +The navigation delegate is set to block navigation to the youtube website, and as the webview background is transparent, you can see scaffold background.