gpt4 book ai didi

java - 通过反射改变 colorPrimary 和 colorAccent

转载 作者:行者123 更新时间:2023-11-29 20:03:57 26 4
gpt4 key购买 nike

我正在尝试以编程方式更改 colorPrimarycolorAccent,但我找不到任何与它们相关的方法,例如 setThemeColorPrimary(int color) 。我找到的唯一方法是通过 Java reflection 更改它.但是,我找不到要反射(reflect)的 colorPrimarycolorAccent 字段。

那么,如何以编程方式更改 colorPrimarycolorAccent

提前致谢。

最佳答案

据我所知,您无法访问 colorAccent 和 colorPrimary 字段,这不是 Android 资源编译过程的工作方式。

没有 Theme.colorPrimary 这样的东西,要访问主题属性,您需要使用 obtainStyledAtributtes() 或类似技术。

我知道以编程方式执行此操作的唯一方法是使用 setTheme() 方法或使用 ContextThemeWrapper()。这两种方式都需要您在 XML 中有多个样式声明。

关于java - 通过反射改变 colorPrimary 和 colorAccent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35893456/

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