From 69b5562fdc385436092f9840b11b29a66c56cc9c Mon Sep 17 00:00:00 2001 From: Crizant Lai Date: Fri, 24 Jul 2020 13:00:32 +0800 Subject: [PATCH] [webview] 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 f9659d9873f4..ae52143597f8 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 @@ -42,7 +42,8 @@ public class FlutterWebView implements PlatformView, MethodCallHandler { 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 0aa2f58f743d..2933f1e93bb2 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 59c87a25dedf..67de10e90e1d 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -16,7 +16,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.