Reputation: 4974
I want to create a selector using the code below:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/sh_radio_icon_checked" />
<item android:state_checked="false" android:drawable="@drawable/sh_radio_icon_unchecked" />
</selector>
So far I have managed to add the first item, like this:
StateListDrawable drawable = new StateListDrawable();
int[] sFocusedSelected = {android.R.attr.state_checked};
Drawable dFocusedSelected = getResources().getDrawable(R.drawable.sh_radio_icon_checked);
drawable.addState(sFocusedSelected, dFocusedSelected);
But do I add the state_checked=false since there's no state_unchecked constant?
Upvotes: 2
Views: 1417
Reputation: 5002
Observe "-" (Minus/Hyphen) in the beginning of "android.R.attr.state_checked"
sld.addState(new int[] {-android.R.attr.state_checked }, greyD);
Android : How to update the selector(StateListDrawable) programmatically
Upvotes: 2