From de4c0efa3a763807f9fbbf128ac165d2a43eb538 Mon Sep 17 00:00:00 2001 From: Andrea Lazzarotto Date: Sun, 26 Feb 2017 20:11:07 +0100 Subject: [PATCH] Enable overlaysWebView on Android API 21+ This patch enables devices running Android API 21+ to have the status bar overlaying the WebView, i.e. `StatusBar.overlaysWebView(true)`. It lets any Android version call `StatusBar.overlaysWebView(false)` to disable the overlay, which is actually the default behavior on that platform. --- src/android/StatusBar.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java index 6c99d781..7b4d946a 100644 --- a/src/android/StatusBar.java +++ b/src/android/StatusBar.java @@ -142,6 +142,23 @@ public void run() { return true; } + if ("overlaysWebView".equals(action)) { + if (Build.VERSION.SDK_INT >= 21) { + this.cordova.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + try { + setStatusBarTransparent(args.getBoolean(0)); + } catch (JSONException ignore) { + LOG.e(TAG, "Invalid boolean argument"); + } + } + }); + return true; + } + else return args.getBoolean(0) == false; + } + return false; } @@ -164,4 +181,21 @@ private void setStatusBarBackgroundColor(final String colorPref) { } } } + + private void setStatusBarTransparent(final boolean transparent) { + if (Build.VERSION.SDK_INT >= 21) { + final Window window = cordova.getActivity().getWindow(); + if (transparent) { + window.getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + window.setStatusBarColor(Color.TRANSPARENT); + } + else { + window.getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_VISIBLE); + } + } + } }