直接在drawable中设置相关的选择器,有时会遇到这种情况:<item> tag requires a 'drawable' attribute"-selector。导致设置颜色不成功
设置方法:
Button中引用android:background="@drawable/button_background_selector"
在文件夹drawable下定义button_background_selector.xml文件,如下:
这种方法在运行时报错如下:
08-17 18:14:42.730:E/AndroidRuntime(24114): Caused by:org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: tag requires a'drawable' attribute or child tag defining a drawable
解决方法:
Button中引用background属性不变
更改button_background_selector.xml文件,如下:
并在colors.xml文件中增加如下定义: