Android transparent selector drawable doesn’t work

May 2015

Today I’ve tried to make selector for my listview. When user selects item it should display arrow right of label. list_highlight Okay. Label is a TextView with drawableRight. And drawableRight links to next selector:

But that code doesn’t work. And here’s the reason why. Initially we doesn’t show an arrow – just transparent color. Color has zero size (0 dp x 0 dp) so when ListView changes state of my CheckedTextView, CheckedTextView changes rightDrawable, but it doesn’t change this size. So solutions is to set max size initially. Blessing, we can point Android framework to do it automatically by adding android:constantSize=”true”. So the final code is:

That’s all!

Leave a Reply

Your email address will not be published. Required fields are marked *