由网友(距离的思念太苦)分享简介:我愿做一个简单的事情:定义绘制具有exacly相同的背景色系统语句pressed背景颜色。我不喜欢这样的RES /可绘制/ my_drawable.xml:I would like to do a simple thing:Define a drawable which has exacly same back...
我愿做一个简单的事情: 定义绘制具有exacly相同的背景色系统语句pressed背景颜色。 我不喜欢这样的RES /可绘制/ my_drawable.xml:
I would like to do a simple thing: Define a drawable which has exacly same background colour as system state-pressed background colour. I do it like this in res/drawables/my_drawable.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="true">
<color android:color="?android:attr/colorPressedHighlight"/>
</item>
<item android:state_selected="false">
<color android:color="@color/section_list_background"/>
</item>
</selector>
我总是得到:
I always get:
java.lang.UnsupportedOperationException: Cant convert to color: type=0x2
任何线索?
问候
推荐答案
您可能需要执行以下操作来解决你的问题:
You might need to do the following to fix your problem:
1)定义2种颜色在你的颜色每个主题文件:
1) Define 2 colors for each theme in your colors file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="my_color_dark">#ff33B5E5</color>
<color name="my_color_light">#ff355689</color>
</resources>
2)创建文件RES /价值/ attrs.xml的内容是:
2) Create file res/values/attrs.xml with contents:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="my_color" format="reference" />
</resources>
3)假设你有2个主题,在你的styles.xml( Theme.dark
和 Theme.light
)定义:
<style name="Theme.dark" parent="@style/Theme.Sherlock">
<item name="my_color">@color/my_color_dark</item>
</style>
<style name="Theme.light" parent="@style/Theme.Sherlock.Light">
<item name="my_color">@color/my_color_light</item>
</style>
4)使用颜色在绘制:
4) Use the color in a drawable:
<color android:color="?attr/my_color"/>
希望这应该解决您的问题。
Hope this should fix your problem.
相关推荐
最新文章