Android Selector Drawable doesnt work with attributes -
i using attr create selector drawable project once change theme colors, dont have make change in drawable file. using following libs:
compile 'com.android.support:appcompat-v7:+' compile 'com.android.support:cardview-v7:+' compile 'com.android.support:design:22.2.0'
here source code drawable:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="?attr/colorprimary" android:state_enabled="true" android:state_window_focused="false"/> <item android:drawable="?attr/colorprimarydark" android:state_pressed="true"/> <item android:drawable="@android:color/darker_gray" android:state_enabled="false"/> <item android:drawable="?attr/colorprimary"/> </selector>
in same code, if replace attributes colors defined in colors.xml file, same drawable works.
sample drawable colors:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/color_primary" android:state_enabled="true" android:state_window_focused="false"/> <item android:drawable="@color/color_primary_dark" android:state_pressed="true"/> <item android:drawable="@android:color/darker_gray" android:state_enabled="false"/> <item android:drawable="@color/color_primary"/> </selector>
thanks in advance!
finally, found problem. there bug in android [pre-lollipop] os doesnt allow use attr in drawable. here link bug:
android dev team has released fix works on android l , above.for workaround problem, refer following solution:
Comments
Post a Comment