【发布时间】:2012-05-08 01:48:22
【问题描述】:
我有一个形状 (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" throws 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>
themes.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>
【问题讨论】: