I have a String with xml's drawable code. I need to use this String inside ImageView like image. And I need to create many such images in activity using kotlin/java code.
I tried to write data to xml file and then convert file to Drawable
/**
* Write text to file
*/
fun stringToDom(xmlSource : String, filePath: String) {
val fw = FileWriter(filePath)
fw.write(xmlSource)
fw.close()
}
//...
val uri : Uri = Uri.parse("android.resource://com.example.package/" + R.drawable.temp)
stringToDom(i, uri.toString())
val d : Drawable = Drawable.createFromXml(context.resources, context.resources.getXml(R.drawable.temp))
//...
And parse xml string with XmlPullParser
val parser : XmlPullParser = Xml.newPullParser();
parser.setInput(StringReader(myXmlString));
val d : Drawable = Drawable.createFromXml(resources, parser)
But all of this doesn't work.