android - ContextThemeWrapper 不适用于样式中定义的属性
问题描述
ContextThemeWrapper 非常适合以编程方式为膨胀视图设置新主题。
这适用于以下情况:
<TextView
android:textColor="?attr/textColorPrimary"
/>
但令人惊讶的是不适用于:
<TextView
style="@style/Label"
/>
<style name="Label">
<item name="android:textColor">?attr/textColorPrimary</item>
</style>
有没有办法让样式从用于膨胀视图的 ContextThemeWrapper 中读取正确的属性值?
解决方案
在这种情况下,您必须应用主题覆盖而不是样式:
<TextView
android:theme="@style/Label"
../>
推荐阅读
- javascript - 如何使 2 个 Quasar 切换按钮组互斥?
- amazon-web-services - CloudTrail 事件中的 AWS 自动 DBSnapshot(系统)
- html - Angular 1.4:在变量中渲染 HTML
- laravel - laravel 文件上传中的 store 和 move 方法以及何时使用其中一种方法有区别吗?
- c - 使用 sendto 函数返回 -1 的原始套接字
- bash - shell:将 grep 输出发送到 stderr 并保持 stdout 不变
- python - 如何为基于另一个列表的嵌套列表添加价值?
- python - 用 numpy 进行多项式拟合:polynomial.Polynomial.fit 的输出错误(但 polyfit 很好)
- python - LoginForm django 模式
- database - 执行请求的操作时遇到错误:ORA-00604: