5

我有一个形状(rect_shape.xml ),它在列表视图( listview_style.xml)的每个项目中绘制一个笔触轮廓。此轮廓应具有与当前主题的默认文本颜色相同的颜色。

有没有办法在 XML中将笔画的 android:color 值设置为当前文本颜色?

我在这里看到了一些类似的问题(例如How to get my own defined attribute value in my style),它们试图设置自己的属性,但我认为这不是我想要的。无论如何我试过了,但我无法将 android:color 值设置为我自己定义的属性(android:color="?custom_stroke_color"抛出 InflateException)。

因为用户能够在主题之间动态切换,所以rect_shape.xml@color/white中的一种预定义颜色(或对颜色资源的引用,例如)不是一个选项。

感谢任何帮助...

rect_shape.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<stroke android:width="3dp"
<!-- should be the current default text color -->
    android:color="#FFF" />

<solid/> 
...
</shape>

listview_style.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rect_shape" >
...
</LinearLayout>

主题.xml

<resources>
<style name="DarkTheme" parent="@style/Theme.Sherlock">
<!-- default text color is white -->
...
</style>
<style name="LightTheme" parent="@style/Theme.Sherlock.Light">
<!-- default text color is black-->
...
</style>
</resources>
4

1 回答 1

0

访问可绘制 XML 文件中的主题属性仅在 android 5.0 及更高版本中可用。

看到这个问题

于 2015-05-27T18:52:50.127 回答