Skip to content

Instantly share code, notes, and snippets.

@EddyVerbruggen
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EddyVerbruggen/fd505e49863714b98b4d to your computer and use it in GitHub Desktop.
Save EddyVerbruggen/fd505e49863714b98b4d to your computer and use it in GitHub Desktop.
Android 5.0 Lollipop statusbar color
// Inside your Activity class onCreate method add and invoke this method.
// Note that you can plug this into any Android project, you don't need to build with SDK 21 to be able to compile
private void setStatusBarColor() {
if (Build.VERSION.SDK_INT >= 21) {
final Window window = getWindow();
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
try {
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
window.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor("#444444"));
} catch (Exception ignore) {
// this should not happen, only in case Android removes this method in a version > 21
Log.w("Bankieren", "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT);
}
}
}
@EddyVerbruggen
Copy link
Author

I've submitted an evolved version of this to the Cordova Statusbar Plugin as a PR which has been accepted and merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment