<!-- ============= -->
<!-- Color palette -->
<!-- ============= -->
<!-- The primary branding color for the app. By default, this is the color applied to the
action bar background. -->
<attr name="colorPrimary" format="color" />
<!-- Dark variant of the primary branding color. By default, this is the color applied to
the status bar (via statusBarColor) and navigation bar (via navigationBarColor). -->
<attr name="colorPrimaryDark" format="color" />
<!-- Bright complement to the primary branding color. By default, this is the color applied
to framework controls (via colorControlActivated). -->
<attr name="colorAccent" format="color" />
<!-- The color applied to framework controls in their normal state. -->
<attr name="colorControlNormal" format="color" />
<!-- The color applied to framework controls in their activated (ex. checked) state. -->
<attr name="colorControlActivated" format="color" />
<!-- The color applied to framework control highlights (ex. ripples, list selectors). -->
<attr name="colorControlHighlight" format="color" />
<!-- The color applied to framework buttons in their normal state. -->
<attr name="colorButtonNormal" format="color" />
<!-- The color applied to framework switch thumbs in their normal state. -->
<attr name="colorSwitchThumbNormal" format="color" />
(来自 Sdk 附加 android 支持 v7 appcompat res value attrs.xml)
fun Activity.coloredStatusBarMode(@ColorInt color: Int = Color.WHITE, lightSystemUI: Boolean? = null) {
var flags: Int = window.decorView.systemUiVisibility // get current flags
var systemLightUIFlag = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
var setSystemUILight = lightSystemUI
if (setSystemUILight == null) {
// Automatically check if the desired status bar is dark or light
setSystemUILight = ColorUtils.calculateLuminance(color) < 0.5
}
flags = if (setSystemUILight) {
// Set System UI Light (Battery Status Icon, Clock, etc)
removeFlag(flags, systemLightUIFlag)
} else {
// Set System UI Dark (Battery Status Icon, Clock, etc)
addFlag(flags, systemLightUIFlag)
}
window.decorView.systemUiVisibility = flags
window.statusBarColor = color
}
private fun containsFlag(flags: Int, flagToCheck: Int) = (flags and flagToCheck) != 0
private fun addFlag(flags: Int, flagToAdd: Int): Int {
return if (!containsFlag(flags, flagToAdd)) {
flags or flagToAdd
} else {
flags
}
}
private fun removeFlag(flags: Int, flagToRemove: Int): Int {
return if (containsFlag(flags, flagToRemove)) {
flags and flagToRemove.inv()
} else {
flags
}
}