-
Notifications
You must be signed in to change notification settings - Fork 180
Open
Description
@SuppressLint("RestrictedApi")
fun updateColorScheme() {
// Create a seed color (e.g., HCT color from ARGB value)
var isDarkMode =
resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
val seedColorInt = themeColor // Hex color value
val typedValue = TypedValue()
val theme = this.theme
theme.resolveAttribute(android.R.attr.colorPrimary, typedValue, true)
val seedColorHct: Hct? = Hct.fromInt(typedValue.data)
// Set contrast level (0.0 for default contrast)
val contrastLevel = 0.0
// Create a SchemeTonalSpot object based on the seed color
val dynamicScheme =
SchemeTonalSpot(seedColorHct, isDarkMode, contrastLevel)
customColorScheme.onPrimaryContainer = dynamicScheme.onPrimaryContainer
customColorScheme.onSecondaryContainer = dynamicScheme.onSecondaryContainer
customColorScheme.onTertiaryContainer = dynamicScheme.onTertiaryContainer
customColorScheme.onPrimaryContainer = getThemeColor(
this,
com.google.android.material.R.attr.colorOnPrimaryContainer
)
customColorScheme.onSecondaryContainer = getThemeColor(
this,
com.google.android.material.R.attr.colorOnSecondaryContainer
)
customColorScheme.onTertiaryContainer = getThemeColor(
this,
com.google.android.material.R.attr.colorOnTertiaryContainer
)
}
Compare the values here when the seed you use is the primary color. You will see the colors for the default theme is darker then the custom theme. It happens only when in day mode. Expected result is same color.
Metadata
Metadata
Assignees
Labels
No labels