set windowlightstatusbar property programmatically

纵然是瞬间 提交于 2020-04-09 17:59:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!