问题
As you know we can set the windowLightStatusBar
from xml by following codes.
<item name="android:windowLightStatusBar">true</item>
i need to change this attribute true to false or false to true by programmatically. Is there a way to achive it?
回答1:
set this if you want to change icons colors
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
and to reset to default set this
.setSystemUiVisibility(0);
but if you want to change background color of statusBar use this
getWindow.setStatusBarColor(ContextCompat.getColor(activity,R.color.my_statusbar_color));
回答2:
I believe this is the correct way to turn on and turn off.
if (on) {
View view = getWindow().getDecorView();
view.setSystemUiVisibility(view.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
View view = getWindow().getDecorView();
view.setSystemUiVisibility(view.getSystemUiVisibility() & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
回答3:
To clear this attribute, use this code:
window.clearFlags( View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
来源:https://stackoverflow.com/questions/42789789/set-windowlightstatusbar-property-programmatically