[英]Is there a way to programmatically get the Android Q System color accent
As you noticed, Google has included a way to select a system wide color accent in the Android settings: 正如您所注意到的,Google已经提供了一种在Android设置中选择系统范围颜色重音的方法:
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/ 我首先想到这不可能在我的应用程序中使用,但是Gboard成功地将它用于主题UI元素,正如我们在此新闻中所看到的: https ://9to5google.com/2019/05/08/android-q -gboard重音色/
I was then wondering if this is a public API, or of there is a way to get it from one way or another. 我当时想知道这是一个公共API,还是有办法从这种或那种方式获得它。
Thanks for any idea. 谢谢你的想法。
You have to use Theme.DeviceDefault
theme as source which independent from AppCompat
world. 您必须使用
Theme.DeviceDefault
主题作为独立于AppCompat
世界的源。
I tested the follow snippet and it works fine when I changed the accent color on Android Q: 我测试了以下代码片段,当我更改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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.