Can you load a drawable from a sub directory in the assets
(not the drawable folder) folder?
original title: "android - Is it possible to load a drawable from the assets folder?"
Can you load a drawable from a sub directory in the assets
(not the drawable folder) folder?
Voitko ladata piirrettävän omakansiohakemiston alahakemistosta?
Tämä on yhteenveto käännöksen jälkeen. Jos haluat tarkastella koko käännöstä, napsauta käännä-kuvaketta
Hope this help:
I recommend to use this
which returns properly scaled drawable thanks to resources ...
Here's a class with static method to get the drawable from the assets. It also closes the inputstream.
Yes you can create a
Drawable
object from anInputStream
using the createFromStream() method.Here is function that does this for you.
Check the returned Drawable variable for null as null may return if the path is invalid or there is an IOException.
This helped getting the right density
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)
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
At this version you can't, if you make a sub folder within your drawable folder you can't use it in your xml file, it won't be recognized when you use android:src.
Take a look at this thread: Can the Android drawable directory contain subdirectories?