【发布时间】:2018-11-19 09:38:43
【问题描述】:
我想根据状态更改 ToggleButton 颜色。我找到了解决方案,但它不起作用。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/buttonA"/>
<item android:state_checked="false" android:color="@color/buttonDisabled"/>
</selector>
我不能使用 android:color,这里只允许使用 android:drawable。 (得到这个例外)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: <item> tag requires a 'drawable' attribute or child tag defining a drawable
【问题讨论】:
-
将您的选择器文件放入
res>color>your_selector.xml
标签: android android-button android-togglebutton