mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12:49 +08:00
refactor(android)!: setStatusBarBackgroundColor (#250)
This commit is contained in:
parent
bb82db9aa9
commit
21847d0b78
@ -169,21 +169,20 @@ public class StatusBar extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusBarBackgroundColor(final String colorPref) {
|
private void setStatusBarBackgroundColor(final String colorPref) {
|
||||||
if (colorPref != null && !colorPref.isEmpty()) {
|
if (colorPref.isEmpty()) return;
|
||||||
final Window window = cordova.getActivity().getWindow();
|
|
||||||
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
|
int color;
|
||||||
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
|
||||||
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
|
||||||
try {
|
try {
|
||||||
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
|
color = Color.parseColor(colorPref);
|
||||||
window.getClass().getMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor(colorPref));
|
|
||||||
} catch (IllegalArgumentException ignore) {
|
} catch (IllegalArgumentException ignore) {
|
||||||
LOG.e(TAG, "Invalid hexString argument, use f.i. '#999999'");
|
LOG.e(TAG, "Invalid hexString argument, use f.i. '#999999'");
|
||||||
} catch (Exception ignore) {
|
return;
|
||||||
// this should not happen, only in case Android removes this method in a version > 21
|
|
||||||
LOG.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Window window = cordova.getActivity().getWindow();
|
||||||
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // SDK 19-30
|
||||||
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // SDK 21
|
||||||
|
window.setStatusBarColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusBarTransparent(final boolean transparent) {
|
private void setStatusBarTransparent(final boolean transparent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user