0

Im using the following code to change the color of status bar. When I try to do so, the app crashes.

Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getApplicationContext().getResources().getColor(Color.BLUE));
Ziem
  • 6,579
  • 8
  • 53
  • 86

2 Answers2

0

getColor(Color.BLUE) getColor takes a Resource identifier i.e. R.color.blue not a static Color constant

Ref:

http://developer.android.com/intl/es/reference/android/content/res/Resources.html#getColor(int)

The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.


This method is also deprecated now and recommended you use the compatibility getColor:

https://stackoverflow.com/a/31590927/413127

Community
  • 1
  • 1
Blundell
  • 75,855
  • 30
  • 208
  • 233
0

put this code

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    window.setStatusBarColor(getResources().getColor(R.color.textblue));
}
Ziem
  • 6,579
  • 8
  • 53
  • 86
Pratik Tank
  • 2,213
  • 1
  • 17
  • 29