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:

https://code.google.com/p/android/issues/detail?id=26251

android dev team has released fix works on android l , above.for workaround problem, refer following solution:

how reference style attributes drawable?


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -