mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12:49 +08:00
CB-14238: Fixed transparency of statusbar
This commit is contained in:
parent
ecf8ccd164
commit
515d683053
@ -39,6 +39,8 @@ import java.util.Arrays;
|
|||||||
public class StatusBar extends CordovaPlugin {
|
public class StatusBar extends CordovaPlugin {
|
||||||
private static final String TAG = "StatusBar";
|
private static final String TAG = "StatusBar";
|
||||||
|
|
||||||
|
private boolean transparent = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the context of the Command. This can then be used to do things like
|
* Sets the context of the Command. This can then be used to do things like
|
||||||
* get file paths associated with the Activity.
|
* get file paths associated with the Activity.
|
||||||
@ -62,6 +64,9 @@ public class StatusBar extends CordovaPlugin {
|
|||||||
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
|
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
|
||||||
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
|
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
|
||||||
|
|
||||||
|
// Read 'StatusBarOverlaysWebView' from config.xml, default is false.
|
||||||
|
setStatusBarTransparent(preferences.getBoolean("StatusBarOverlaysWebView", false));
|
||||||
|
|
||||||
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
|
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
|
||||||
setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent"));
|
setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent"));
|
||||||
}
|
}
|
||||||
@ -96,7 +101,11 @@ public class StatusBar extends CordovaPlugin {
|
|||||||
// use KitKat here to be aligned with "Fullscreen" preference
|
// use KitKat here to be aligned with "Fullscreen" preference
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
int uiOptions = window.getDecorView().getSystemUiVisibility();
|
int uiOptions = window.getDecorView().getSystemUiVisibility();
|
||||||
|
if (StatusBar.this.transparent) {
|
||||||
|
uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
||||||
|
} else {
|
||||||
uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
||||||
|
}
|
||||||
uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
|
uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||||
|
|
||||||
window.getDecorView().setSystemUiVisibility(uiOptions);
|
window.getDecorView().setSystemUiVisibility(uiOptions);
|
||||||
@ -227,21 +236,23 @@ public class StatusBar extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusBarTransparent(final boolean transparent) {
|
private void setStatusBarTransparent(final boolean transparent) {
|
||||||
if (Build.VERSION.SDK_INT >= 21) {
|
this.transparent = transparent;
|
||||||
final Window window = cordova.getActivity().getWindow();
|
final Window window = cordova.getActivity().getWindow();
|
||||||
if (transparent) {
|
if (transparent) {
|
||||||
window.getDecorView().setSystemUiVisibility(
|
window.getDecorView().setSystemUiVisibility(
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
window.setStatusBarColor(Color.TRANSPARENT);
|
window.setStatusBarColor(Color.TRANSPARENT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
window.getDecorView().setSystemUiVisibility(
|
window.getDecorView().setSystemUiVisibility(
|
||||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
| View.SYSTEM_UI_FLAG_VISIBLE);
|
| View.SYSTEM_UI_FLAG_VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void setStatusBarStyle(final String style) {
|
private void setStatusBarStyle(final String style) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
Loading…
Reference in New Issue
Block a user