Android Lollipop Set Status Bar Text Color

后端 未结 7 1143
遇见更好的自我
遇见更好的自我 2020-12-14 06:30

I\'m trying to set the status bar text color in Android v21, but I\'m not seeing an API method for it. Here\'s what I have so far for the background

MyActivity.java

7条回答
  •  不思量自难忘°
    2020-12-14 07:12

    You can also do this at runtime. Here is an example for Mono.Android using the flag SystemUiVisibility. You have to do some bitwise operations to change the flag. Your application must be set to target API 23 or higher to compile with this flag.

    //Android 6.0 introduced the ability to set a light colored text on the status bar
    //MyActivity needs to be changed to your activity
    
    if(Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.M)
    {
        int newUiVisibility = (int)MyActivity.Window.DecorView.SystemUiVisibility;
    
        if(state == StatusBarState.Light)
        {
            //Dark Text to show up on your light status bar
            newUiVisibility |= (int)Android.Views.SystemUiFlags.LightStatusBar;
        }
        else if(state == StatusBarState.Dark)
        {
            //Light Text to show up on your dark status bar
            newUiVisibility &= ~(int)Android.Views.SystemUiFlags.LightStatusBar;
        }
    
        MyActivity.Window.DecorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)newUiVisibility;
    }
    
    public enum StatusBarState
    {
        Light,
        Dark
    }
    

提交回复
热议问题