2012-04-27 64 views
5

当前主题默认文本颜色我有一个形状( rect_shape.xml)绘制一个笔画轮廓在ListView( listview_style.xml)的每一个项目。 此轮廓应具有与当前主题的默认文本颜色相同的颜色。如何获得(参考)在XML

有没有什么办法,在XML,把笔画的android:color值设置为当前的文字颜色?

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

因为用户能够在主题之间切换动态地,一个单一的预定的颜色(或参考颜色资源例如@color/white)在 rect_shape.xml不是一个选项。

感谢所有帮助...

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> 

回答

0

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

请参阅This issue