As you noticed, Google has included a way to select a system wide color accent in the Android settings:
I first thought this would be impossible to use in my app, but Gboard succeed to use it to theme UI elements accordingly, as we can see in this news: https://9to5google.com/2019/05/08/android-q-gboard-accent-color/
I was then wondering if this is a public API, or of there is a way to get it from one way or another.
Thanks for any idea.
Accent color This helps accented elements stand out. Use accent colors sparingly to accent key elements, such as text or buttons.
The primary color is the color displayed most frequently across your app's screens and components. The primary variant color is used to distinguish two elements of the app using the primary color, such as the top app bar and the system bar. The secondary color provides more ways to accent and distinguish your product.
The accent color is used more subtly throughout the app, to call attention to key elements. The resulting juxtaposition of a tamer primary color and a brighter accent, gives apps a bold, colorful look without overwhelming the app's actual content. Save this answer.
You have to use Theme.DeviceDefault
theme as source which independent from AppCompat
world.
I tested the follow snippet and it works fine when I changed the accent color on Android Q:
@ColorInt
fun getDeviceAccentColor(context: Context) : Int {
val value = TypedValue()
val ctx = ContextThemeWrapper(context, android.R.style.Theme_DeviceDefault)
ctx.theme.resolveAttribute(android.R.attr.colorAccent, value, true)
return value.data
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With