0

The app starts with status bar color:

Background white, the text is black.

When entering modal pop up screen, status bar changes to back, with white text:

window?.setStatusBarColor(Color.BLACK);
activity?.window?.decorView?.systemUiVisibility = SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR

Works!

Next, on modal popup screen dismiss, I would like the status bar to go back to normal:

background white, and black text

with no luck.

What did I try? This:

window?.setStatusBarColor(Color.BLACK); // This really does work
activity?.window?.decorView?.systemUiVisibility = // Not sure what should be the value

Status bar background does change, but not text. Not sure what systemUiVisibility value should be.

Read https://developer.android.com/reference/android/view/View But didn't find anything suitable, tried

SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_STABLE

Still no luck.

MCMatan
  • 8,623
  • 6
  • 46
  • 85

2 Answers2

0

I don't code in Kotlin, but the following code snippet will do the trick

Window window = activity.getWindow();

// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

// finally change the color
window.setStatusBarColor(ContextCompat.getColor(activity,R.color.my_statusbar_color));

It should automatically change the Text color as well.

Reference

Source

Daksh Gargas
  • 3,498
  • 2
  • 23
  • 37
  • Didn't work. The text still stays white... And this code does not deal with text color change, only the background color... – MCMatan Oct 09 '18 at 12:16
0

You would need to set the decorView's systemUiVisibility to have the following flag turned on View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.

In your case

activity?.window?.decorView?.systemUiVisibility = activity?.window?.decorView?.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
Thalatta
  • 4,510
  • 10
  • 48
  • 79