android - Android:继承样式并在其中设置自定义属性的值不起作用
问题描述
我有一个自定义属性attr.xml
:
<resources>
<attr name="buttonBackgroundColor" format="reference"/>
</resources>
我创建了一个button_background.xml
使用该自定义属性的drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?buttonBackgroundColor"/>
<corners android:radius="7dp" />
</shape>
我定义了如下风格:
<style name="button_background">
<item name="android:background">@drawable/button_background</item>
<item name="android:elevation">3dp</item>
<item name="android:textStyle">bold</item>
<item name="android:paddingTop">15dp</item>
<item name="android:paddingBottom">15dp</item>
<item name="android:gravity">center</item>
</style>
我在这些子样式中定义该自定义属性的值:
<style name="button_background_green" parent="button_background">
<item name="buttonBackgroundColor">@color/Green</item>
</style>
<style name="button_background_blue" parent="button_background">
<item name="buttonBackgroundColor">@color/Blue</item>
</style>
我button_background_green
在 a 中使用麦粒肿TextView
:
<TextView
android:id="@+id/done"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="@style/button_background_green"
android:textSize="17sp"
android:text="@string/done" />
我认为这就是我们实现具有许多共同属性但不起作用的样式的方式。如果我将android:background
属性设置为子样式的颜色,它会完美运行。所以我认为由于某种原因它无法读取buttonBackgroundColor
属性。请帮忙。我真的很感激。
解决方案
推荐阅读
- ruby-on-rails - ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):Rails 5
- javascript - 在 JavaScript 的日期数组中找不到日期
- android - 如何在 Ionic 源代码中指定用户权限
- python - 字符串到 int - 错误
- python - 绘制包含 NaN 值的 pandas 数据框列
- regex - Grep 中的正则表达式错误“重复之前没有有效的表达式”
- jsf - 更改订单时访问 DataTable 项返回不正确的选定项
- python-3.x - ImportError:libcublas.so.9.0:没有这样的文件或目录
- html - 考虑到滚动条,如何使固定标题居中?
- java - org.postgresql.util.PSQLException:错误:函数 st_geomfromkml(unknown) 不存在