change tint of status bar android

Solutions on MaxInterview for change tint of status bar android by the best coders in the world

showing results for - "change tint of status bar android"
Alessandro
02 Jan 2021
1/**
2 * @param colorId id of color
3 * @param isStatusBarFontDark Light or Dark color
4 */
5fun updateStatusBarColor(@ColorRes colorId: Int, isStatusBarFontDark: Boolean = true) {
6    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
7        val window = window
8        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
9        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
10        window.statusBarColor = ContextCompat.getColor(this, colorId)
11        setSystemBarTheme(isStatusBarFontDark)
12    }
13}
14
15/** Changes the System Bar Theme.  */
16@RequiresApi(api = Build.VERSION_CODES.M)
17private fun setSystemBarTheme(isStatusBarFontDark: Boolean) {
18    // Fetch the current flags.
19    val lFlags = window.decorView.systemUiVisibility
20    // Update the SystemUiVisibility depending on whether we want a Light or Dark theme.
21    window.decorView.systemUiVisibility = if (isStatusBarFontDark) lFlags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() else lFlags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
22}