Android добавить LayerDrawable в StateListDrawable - PullRequest
0 голосов
/ 01 апреля 2020

Я пытаюсь создать StateListDrawable с LayeredDrawables, но получаю следующую ошибку:

W/LayerDrawable: Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state.
java.lang.RuntimeException

Мой код:

val checked = LayerDrawable(arrayOf(checkedBackground, checkedDrawable))
val unchecked =  LayerDrawable(arrayOf(uncheckedBackground, uncheckedDrawable))

val statelist = StateListDrawable()
statelist.addState(intArrayOf(android.R.attr.state_checked), checked)
statelist.addState(StateSet.WILD_CARD, unchecked) //<-- here the error occurs
icon.background = statelist
...