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

前端 未结 10 1688
自闭症患者
自闭症患者 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:26

    Set blue background status bar with light text color kotlin version

    fun setBlueStatusBarColor(window: Window, context: Context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                window.statusBarColor = context.getColor(R.color.colorBlue)
            }else {
                window.statusBarColor = context.resources.getColor(R.color.colorBlue)
            }
    
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                var flags: Int = window.decorView.systemUiVisibility
                flags = flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
                window.decorView.systemUiVisibility = flags
            }
        }
    }
    

提交回复
热议问题