Skip to content

Commit 65a8631

Browse files
committed
CB-14238: Make transparency of statusbar persistent when hiding and showing statusbar
1 parent ecf8ccd commit 65a8631

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/android/StatusBar.java

+23-12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
public class StatusBar extends CordovaPlugin {
4040
private static final String TAG = "StatusBar";
4141

42+
private boolean transparent = false;
43+
4244
/**
4345
* Sets the context of the Command. This can then be used to do things like
4446
* get file paths associated with the Activity.
@@ -62,6 +64,9 @@ public void run() {
6264
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
6365
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
6466

67+
// Read 'StatusBarOverlaysWebView' from config.xml, default is false.
68+
setStatusBarTransparent(preferences.getBoolean("StatusBarOverlaysWebView", false));
69+
6570
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
6671
setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent"));
6772
}
@@ -96,7 +101,11 @@ public void run() {
96101
// use KitKat here to be aligned with "Fullscreen" preference
97102
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
98103
int uiOptions = window.getDecorView().getSystemUiVisibility();
99-
uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
104+
if (StatusBar.this.transparent) {
105+
uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
106+
} else {
107+
uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
108+
}
100109
uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
101110

102111
window.getDecorView().setSystemUiVisibility(uiOptions);
@@ -227,19 +236,21 @@ private void setStatusBarBackgroundColor(final String colorPref) {
227236
}
228237

229238
private void setStatusBarTransparent(final boolean transparent) {
230-
if (Build.VERSION.SDK_INT >= 21) {
231-
final Window window = cordova.getActivity().getWindow();
232-
if (transparent) {
233-
window.getDecorView().setSystemUiVisibility(
234-
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
235-
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
239+
this.transparent = transparent;
240+
final Window window = cordova.getActivity().getWindow();
241+
if (transparent) {
242+
window.getDecorView().setSystemUiVisibility(
243+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
244+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
245+
246+
if (Build.VERSION.SDK_INT >= 21) {
236247
window.setStatusBarColor(Color.TRANSPARENT);
237248
}
238-
else {
239-
window.getDecorView().setSystemUiVisibility(
240-
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
241-
| View.SYSTEM_UI_FLAG_VISIBLE);
242-
}
249+
}
250+
else {
251+
window.getDecorView().setSystemUiVisibility(
252+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
253+
| View.SYSTEM_UI_FLAG_VISIBLE);
243254
}
244255
}
245256

0 commit comments

Comments
 (0)