0

I am trying to clear the View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR flag so that the status bar icons become default white for my dark status bar background.

The issue is the following code is working perfectly if I naviagte to activity but it does not work if I use the same code for fragments.

For Clearing Flags I am using this: 
getActivity().getWindow().clearFlags(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.my_calender_appbar_background));

For Setting Flag:getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.white));
Zoe
  • 27,060
  • 21
  • 118
  • 148
ALI REHMAN
  • 23
  • 9

1 Answers1

0

To enable windowLightStatusBar(programatically,inside a Utils class for example):

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); 
        }
}

To restore to StatusBar to the previous state:

public static void clearLightStatusBar(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Window window = activity.getWindow();
        window.setStatusBarColor(ContextCompat
             .getColor(activity,R.color.colorPrimaryDark)); 
    }
}
Akshay Kumar S
  • 333
  • 3
  • 12