Android M Light and Dark status bar programmatically - how to make it dark again?

前端 未结 10 1689
自闭症患者
自闭症患者 2020-12-24 10:49

In the Android M we have ability to make status bar icons dark. To do that we can specify attribute in the theme\'s xml:



        
10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-24 11:31

    i will make some changes in above answers.

    make a class

     public class DarkStatusBar {
        public static void setLightStatusBar(View view, Activity activity){
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    
                int flags = view.getSystemUiVisibility();
                flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
                view.setSystemUiVisibility(flags);
                activity.getWindow().setStatusBarColor(Color.WHITE);
            }
        }
    }
    

    and Call it wherever you want like this

            Window window = getWindow();
            View view = window.getDecorView();
            DarkStatusBar.setLightStatusBar(view,this);
    

提交回复
热议问题