Is it possible to load a drawable from the assets folder?

后端 未结 8 1646
刺人心
刺人心 2020-12-08 06:43

Can you load a drawable from a sub directory in the assets (not the drawable folder) folder?

相关标签:
8条回答
  • 2020-12-08 07:15

    Yes you can create a Drawable object from an InputStream using the createFromStream() method.

    0 讨论(0)
  • 2020-12-08 07:18

    I was working in a RecyclerView adapter and found that David's answer was not working for me, (for some reason asset.open remained Unresolved no matter what I imported )

    so I found this to work for me (Kotlin code)

    val d = Drawable.createFromStream(context?.assets?.open("imageData/${imageName}.png"), null)
    

    here is my directory, as you can see the assets start from the assets folder and here is a link on how to create that assets folder

    0 讨论(0)
提交回复
热议问题