Android M Light and Dark status bar programmatically - how to make it dark again?

前端 未结 10 1685
自闭症患者
自闭症患者 2020-12-24 10:49

In the Android M we have ability to make status bar icons dark. To do that we can specify attribute in the theme\'s xml:



        
10条回答
  •  自闭症患者
    2020-12-24 11:20

    /**
     * Changes color of the status bar icons
     * @param isLight if true - shows dark icons, light else
     */
    fun setStatusBarUiTheme(activity: Activity?, isLight: Boolean) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            activity?.window?.decorView?.let {
                it.systemUiVisibility = if (isLight)
                    it.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR // dark icons
                else
                    it.systemUiVisibility and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() // light icons
            }
        }
    }
    

提交回复
热议问题