How to change the status bar color in Android?

后端 未结 21 2022
旧时难觅i
旧时难觅i 2020-11-21 16:09

First of all it\'s not a duplicate as in How to change the background color of android status bar

How do I change the status bar color which should be same as in nav

21条回答
  •  长发绾君心
    2020-11-21 16:26

    You can use this simple code:

    One-liner in Kotlin:

    window.statusBarColor = ContextCompat.getColor(this, R.color.colorName)
    

    Original answer with Java & manual version check:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorAccentDark_light, this.getTheme()));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorAccentDark_light));
    }
    

提交回复
热议问题