android - Wrapping a StateListDrawable -


i have view, on set statelistdrawable (defines state_pressed , default state) background in xml. works fine, states displayed expected.

i want programmatically draw on top of statelistdrawable, no matter in state is. this, created java class extends drawable, holds original background drawable; in ondraw first draws original drawable canvas , own additions. works, state of original drawable doesn't change.

i can see setstate of custom drawable called stateset contains android.r.attr.state_pressed among other states. delegate call original drawable, there setstate returns false , state doesn't change. changes when pass stateset containing nothing android.r.attr.state_pressed.

it seems if statelistdrawable somehow can announce statesets interested in , caller of setstate respecting that, although didn't find related in docs or android source.

this setstate:

@override public boolean setstate(int[] stateset) {     boolean changed = super.setstate(stateset);     if (originalbackground != null) {         // call returns true , changes state if         // stateset *only* contains pressed state         changed |= originalbackground.setstate(stateset);     }     return true; } 

my original background drawable:

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_pressed="true"           android:drawable="@color/red"/>     <item android:drawable="@color/green"/> </selector> 

how can make original drawable change state without filtering stateset state_pressed?

thanks pskink's example tried calling invalidateself in onstatechanged, did trick.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -