TL;DR Я ищу реализацию public static Drawable getDrawableFromAttribute(Context context, String attrName)
.
Я ищу способ загрузить динамические чертежи, которые определены в моем стиле с помощью настраиваемых атрибутов. Это моя конфигурация
attr.xml
<resources>
<attr name="custom_image" type="reference">
</resources>
styles.xml
<resources>
<style name="demo">
<item name="custom_image">@drawable/fancy_picture</item>
</style>
</resources>
fancy_picture имеет имя /res/drawables/fancy_pictures.xml.
Теперь я хочу, чтобы кто-то ввел строку «custom» и «image», и ImageView
должен показать в ней fancy_picture.
Как лучше всего это сделать? Если бы я использовал файл XML-Layout, я мог бы написать
<ImageView
...
android:src="?custom_image"
...
/>
Я не использовал declare-styleable в своем стиле xml и хотел бы полностью их игнорировать, если это возможно.