In my current project,I need to iterate each of the child drawable in StateListDrawable.
In the source code of the StateListDrawable.java, I find a method:
public Drawable getStateDrawable(int index)
but the annotation of this method is @hide, which means I can not use it.
So, is there any alternative way to achieve this?
This is a fairly old question now, so it's probably too late to help you, but for the sake of anyone else who finds it I was able to do it with this code:
final DrawableContainer parentDrawable = (DrawableContainer) drawable;
final DrawableContainerState containerState = (DrawableContainerState) parentDrawable.getConstantState();
final Drawable[] children = containerState.getChildren();
for (int i = containerState.getChildCount(); i > 0; --i) {
doStuff(children[i - 1]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With