Iterate child accessible by StateListDrawable in android

In my current project, I need to iterate each of the children available in StateListDrawable.

In the source code of StateListDrawable.java, I find a method:

public Drawable getStateDrawable (index int)

but the annotation of this method is @hide, which means that I cannot use it.

So, is there an alternative way to achieve this?

+4
source share
1 answer

This is a pretty old question now, so it may be too late to help you, but for the sake of someone who found it, I was able to do this 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]); } 
+3
source

Source: https://habr.com/ru/post/1440182/


All Articles