gpt4 book ai didi

android - 有没有办法以编程方式获取 Android Q 系统颜色强调

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:56:48 25 4
gpt4 key购买 nike

正如您所注意到的,Google 在 Android 设置中提供了一种选择系统范围颜色强调的方法:

enter image description here

我最初认为这不可能在我的应用程序中使用,但 Gboard 成功地使用它来相应地为 UI 元素设置主题,正如我们在这条新闻中看到的:https://9to5google.com/2019/05/08/android-q-gboard-accent-color/

然后我想知道这是否是一个公共(public) API,或者是否有办法从某种方式获取它。

谢谢你的想法。

enter image description here

最佳答案

您必须使用 Theme.DeviceDefault 主题作为独立于 AppCompat 世界的来源。

我测试了以下代码 fragment ,当我在 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
}

关于android - 有没有办法以编程方式获取 Android Q 系统颜色强调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56072467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com