Reputation: 51
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?
Upvotes: 5
Views: 582
Reputation: 1724
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]);
}
Upvotes: 5