Android Lollipop Set Status Bar Text Color

后端 未结 7 1157
遇见更好的自我
遇见更好的自我 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:20

    Here's a Java implementation of Gandalf458's answer.

    /** Changes the System Bar Theme. */
    @RequiresApi(api = Build.VERSION_CODES.M)
    public static final void setSystemBarTheme(final Activity pActivity, final boolean pIsDark) {
        // Fetch the current flags.
        final int lFlags = pActivity.getWindow().getDecorView().getSystemUiVisibility();
        // Update the SystemUiVisibility dependening on whether we want a Light or Dark theme.
        pActivity.getWindow().getDecorView().setSystemUiVisibility(pIsDark ? (lFlags & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) : (lFlags | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR));
    }
    

提交回复
热议问题