androidandroid-statusbarxiaomimiui

Translucent Status Bar Miui devices


I want to set the status bar to translucent on devices running MIUI. I can't find a solution to this problem.

I've tried doing it like this:

activity.window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLCUENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

and similarly when I want to remove the translucent status bar

activity.window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

It works on most devices (I haven't tried all of them) but it doesn't work on MIUI devices. I've tried it on Xiaomi Redmi Note 4 running Android 7.0 (Nougat). Transparent status bar works normally, but translucent doesn't.


Solution

  • To make it work on all devices you have to do :

    fun setTranslucent(activity : Activity){
        activity.window.statusBarColor = 0x66000000
    }
    
    fun clearTranslucent(activity : Activity){
        activity.window.statusBarColor = Color.TRANSPARENT
    }
    

    this code works on devices running MIUI as well. I don't know why flags won't work, may be it's because MIUI devices draw status bar in some strange way. If you know why I'd be more than happy to hear it :)