Last active
August 29, 2015 14:16
-
-
Save EddyVerbruggen/fd505e49863714b98b4d to your computer and use it in GitHub Desktop.
Android 5.0 Lollipop statusbar color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've submitted an evolved version of this to the Cordova Statusbar Plugin as a PR which has been accepted and merged!