39
39
public class StatusBar extends CordovaPlugin {
40
40
private static final String TAG = "StatusBar" ;
41
41
42
+ private boolean transparent = false ;
43
+
42
44
/**
43
45
* Sets the context of the Command. This can then be used to do things like
44
46
* get file paths associated with the Activity.
@@ -62,6 +64,9 @@ public void run() {
62
64
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
63
65
setStatusBarBackgroundColor (preferences .getString ("StatusBarBackgroundColor" , "#000000" ));
64
66
67
+ // Read 'StatusBarOverlaysWebView' from config.xml, default is false.
68
+ setStatusBarTransparent (preferences .getBoolean ("StatusBarOverlaysWebView" , false ));
69
+
65
70
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
66
71
setStatusBarStyle (preferences .getString ("StatusBarStyle" , "lightcontent" ));
67
72
}
@@ -96,7 +101,11 @@ public void run() {
96
101
// use KitKat here to be aligned with "Fullscreen" preference
97
102
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .KITKAT ) {
98
103
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
+ }
100
109
uiOptions &= ~View .SYSTEM_UI_FLAG_FULLSCREEN ;
101
110
102
111
window .getDecorView ().setSystemUiVisibility (uiOptions );
@@ -227,19 +236,21 @@ private void setStatusBarBackgroundColor(final String colorPref) {
227
236
}
228
237
229
238
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 ) {
236
247
window .setStatusBarColor (Color .TRANSPARENT );
237
248
}
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 );
243
254
}
244
255
}
245
256
0 commit comments