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

后端 未结 8 1674
刺人心
刺人心 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: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

提交回复
热议问题