Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

status bar font color not changing synchronously

Tags:

android

I am changing the decorView of my window to basically toggle between View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR being true and false depending upon a scroll position of my view.

Since I am changing the ActionBar and the status Bar at the same time, I would like both changes to at least be perceptibly instantaneous. However I notice there is a 50ms delay between window.decorView.systemUiVisibility = newIntWithToggledLightMode being executed and the new status bar mode being rendered. I don't want to have my toolbar changes be placed in a postDelay handler just to coordinate their appearance of simultaneity with the status bar change. I thought I could override onSystemUiVisibilityChangeInterface to be informed when the status bar ui had been updated but that only seems triggered when I make the status bar invisible, not simply changing the appearance mode. Has anybody run into this and come up with a more elegant solution?

like image 269
Thalatta Avatar asked Apr 23 '19 22:04

Thalatta


People also ask

How to change the color of the status bar text?

If you use setSystemUIOverlayStyle to control your status bar text color, you can easily change your style by calling SystemChrome.setSystemUIOverlayStyle (SystemUiOverlayStyle.light) again. No variable or set state needed. <1> Start with white status bar text color. <2> Tap the button will change it to black.

Does the annotatedregion widget change the text color of the status bar?

Status bar text color change according to our FakeAppBar. If the AnnotatedRegion widget isn't placed around the top area, the value won't be used. This makes perfect sense since the widget color won't interfere with the status bar, so it shouldn't affect the status bar style.

Can fakeappbar change the status bar style dynamically?

FakeAppBar won't have an effect on the status bar style if it doesn't sit at the top part of the screen. You can change style dynamically just like an app bar with variable and setState because internally, AppBar also uses AnnotatedRegion.

How to create fake app bar using annotatedregion?

Here is fake app bar I created using AnnotatedRegion. It is a simple pink bar with a white status bar text color. Place this AnnotatedRegion widget around the top area, and the system will configure the system styles based on its value. <1> Put it at the very top.


1 Answers

I just investigated trying to replicate your issue, but I did not encountered the latency that you are talking about... In my example, I simulated the changing background event with a button click. Hoping that it will help you, I share my code here:

activity's attribute

private val isLight get () = (window.decorView.systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) > 0

button initialization in activity's onCreate

button.setOnClickListener {
    if (isLight) {
        setStatusBarColors(
            decorView.systemUiVisibility and SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv(),
            ContextCompat.getColor(decorView.context, android.R.color.holo_green_dark)
        )
    } else {
        setStatusBarColors(
            decorView.systemUiVisibility or SYSTEM_UI_FLAG_LIGHT_STATUS_BAR,
            ContextCompat.getColor(decorView.context, android.R.color.holo_red_light)
        )
    }
}

and the setStatusBarColors() function

private fun setStatusBarColors(flags: Int, @ColorInt bgColor: Int) {
    window.decorView.systemUiVisibility = flags
    window.statusBarColor = bgColor
    toolbar.setBackgroundColor(bgColor)
}

This code lead to the following result (click on the following GIF if it does not run): enter image description here

like image 62
Wang Avatar answered Oct 19 '22 17:10

Wang