To change status bar color use setStatusBarColor(int color).
According the javadoc, we also need set some flags on the window.
Working snippet of code:
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(ContextCompat.getColor(activity, R.color.example_color));
Keep in mind according Material Design guidelines status bar color and action bar color should be different:
- ActionBar should use primary 500 color
- StatusBar should use primary 700 color
Look at the screenshot below: