Fast ways to import drawables in Android Studio?
Solution 1
This became a lot easier since Android Studio 3.4.
Simply go to the Resource Manager
-tab and click the little add-button add resources to the module
.
[
Then select the drawables you would like to import. If you placed the drawables in folders with the same name like the qualifiers (drawable-mdpi, drawable-hdpi. drawable-xhdpi and so on), the tool will automatically know were to add them.
The only thing still missing in my opinion is adding the drawables to a certain flavorDimension.
Solution 2
Check android-drawable-importer-intellij-plugin
Solution 3
My Answer on Jan 16, 2017.
Two years later, Android Studio has a way to import Image Assets
. But I wanted to add a new comment. Android now supports Vectors
, so we don't have to worry about different resolutions. I suggest to use Vector
and VectorDrawable
.
Just right click your app name in the Project -> New -> Vector Asset
.
Just follow the wizard.
Best regards, Pedro.
My Answer on Feb 18, 2015.
If I don't misunderstood, this is what I do in my Android Studio (AS) projects.
I found out that we only need to import the highest resolution resource; AS will scale them for you. I ask my designers to only generate xxhdpi files and then.
You go to your /res
folder in the Project
navigator, right click and select New -> Image Asset
Asset Studio
will pop up
In there you can,
- Select your asset type
[ Launcher Icon, Action bar icons, Notification icons ]
- Browse you original file
- Name your resource
After you have completed all the information. Your resource will be imported in AS.
As a general note. For inner icons other than the launcher icons, I selected as type "launch icon", and they work perfectly.
Hope this help.
Best, Pedro.
Solution 4
As Rob Meeuwisse mentioned in a comment above, you can do it in one copy and paste action. Rather than copy and paste each of the files one by one, you can instead select all four drawable-XXXX
folders (not the images themselves!) in your OS file manager at the same time (by Ctrl
-clicking in Windows/Linux or Command
-clicking in OS X), copy all these folders and then paste them into the res
folder in Android Studio.
The images will automatically be pasted into the appropriate drawable folder in res
. This works because if Android Studio notices that you're copying and pasting a folder that already exists in the project, it will simply use the existing folder and paste in what's missing rather than replace/discard the files that are already there.
Solution 5
I usually do it in a very simple way: I use this tool to generate my images directly in the right folders names: you just have to open the tool and drag on it the bigger image (EG: the one you want to use for xhdpi folder or xxhdpi folder): the tool will create in the original image's folder all the other folders (mdpi,ldpi,hdpi etc) containing the image properly scaled. Once you have this folders you just have to paste them in res folder, DONE!
natario
Updated on June 26, 2020Comments
-
natario almost 4 years
At some point in an Android project you will need to import some drawables - be it toolbar icons, images, UI features - in
res/drawable
directory. Most of the times you have images scaled for the most common qualifiers (drawable-hdpi
,drawable-mdpi
,drawable-xdpi
,drawable-xxdpi
, ...).So we need to do three, four, even five file copy/pastes for each drawable:
external_dir/drawable-mdpi/file.png -> my_package/drawable-mdpi/file.png external_dir/drawable-hdpi/file.png -> my_package/drawable-hdpi/file.png external_dir/drawable-xdpi/file.png -> my_package/drawable-xdpi/file.png external_dir/drawable-xxdpi/file.png -> my_package/drawable-xxdpi/file.png
That is annoying if you have to import multiple pics. Is there an easy, quick way to transfer these four instances of
file.png
right in the corresponding package folder? Some function implemented in the IDE? Some easy workaround?My workflow until now has been:
- copy/paste from OS file manager, from the external directory to the package, and then refresh the resource files in Android Studio. That implies opening each one of the qualified subdirectories, so four moves;
- from the OS file manager, move to
external_dir
, search forfile.png
, get the four instances in a single list, drag&drop into Android Studio, then for each pic right click on the nav bar,Copy
, andPaste
in the corresponding package directory. Not really better!
Any advice?
Edit - I'm not really asking for "advices" of course - I want to know if there's a way to drop the number of moves to one (or such).
-
natario about 9 yearsCouldn't believe there was not a built-in tool. Thank you.
-
natario about 9 yearsThank you. I accepted this answer because it, well, answers, plus points to a tool that will be useful also in different situations.
-
IntelliJ Amiya about 9 yearsGood answer . Perfect
-
Steven Byle about 9 yearsI would not recommend this, those icon types have set sizes (in dp), and if your custom asset is not one of those specific sizes, Android studio will scale your icon to meet whichever icon type size that you pick, making your icon either larger or smaller than you intended...
-
natario about 9 years@Steven sorry, I didn't get it. You mean it's risky because you have to use an icon of the exact right size, otherwise it would be scaled wrong?
-
Steven Byle about 9 years@miav Sort of, I mean Android forces the icon it generates to be the proper size of that icon type (launcher = 48dp, action bar = 32dp, notification = 24dp). If you have a custom icon that is 36dp x 36dp (108x108px @ xxhdpi), and you choose launcher, the icon it generates will be 48x48dp (144x144px @ xxhdpi), which is not the size you intended to import. I made the same mistake when first trying to import with AS, and realized afterwards the icons AS was putting in was not the size in dp that I started with.
-
natario about 9 years@Steven got it, nice to know. If one could set desired size in dps this would be a pretty complete tool.
-
Pedro Varela about 9 years@StevenByle yeap, you are right, I haven't realized about that, as my apps seems to look well I posted this a possible solution. So, do you know what is correct way to import assets in AS?
-
Pedro Varela about 9 years@StevenByle yeap, you are right, I had not realize it, as my apps seems to look well I posted it a possible solution. So, do you know what is correct way to import assets in AS
-
Steven Byle about 9 years@PedroVarela I unfortunately do not have an answer (that's how I ended up on this question). I tried the plugin referenced in the accepted answer, but it looks like it has a bug with AS 1.0.2 and does not show up, which was logged against it in GitHub.
-
natario about 9 yearsYep - but not useful if your
drawable-XXXX
folders have hundreds of files, only one of which needs to be imported (this is the most common case for me, as I tend to import icons from material sets) -
the_prole over 8 yearsWhy doesn't this method work for me? There is no new directory created when I import a png file.
-
Pedro Varela about 8 yearsHello everyone, After a while the designer of the company I worked, told me about and script that helped them export from illustrator to different resolutions, he send me the script, I don't know who is the author, so I read it, improved it and tested it, and it does exactly what we wanted, custom assets with different resolutions. Heres the link {dl.dropboxusercontent.com/u/592105/SaveAndroid.jsx} It takes the illustrator artboard and export it to png. Hope it helps you.
-
Arjun Anil over 6 yearsWhy does using this make my app laggy.I have one image and i convert it using this software.But it makes my app very laggy
-
xarlymg89 over 5 yearsNow there's only one thing missing to make your answer perfect. There should be an easy way of importing several SVGs into an Android project with Android Studio. I'm still looking for it. Sometimes it can be a bit tiring to manually import, for example, 10-20 SVGs.
-
sushrut619 about 5 yearsWhen I tired importing an image with 'Adaptive and Legacy' option instead of 'Legacy' only, the image was being rendered in a circle on the app. The preview would show it as a square (desired view) but in the app it was rendered in a circle within the square layout. Can anyone explain this behaviour ? When I imported the image using only 'Legacy' option it rendered correctly as a square
-
Ali Alaoi about 4 years@DragonFire, Yes I face same issue.
-
MaKi about 4 yearsi am also facing same issue in 3.6.1
-
Luis Aguilar almost 4 yearsThis plugin is not working for android studio 3.6 and so on but, I found this answer that worked for me: StackOverFlow answer. Download drawable importer from here
-
LSG almost 4 years@PedroVarela you asked to use vector asset. How could I use coloured image as a vector asset? Whenever I am converting the coloured png image to svg, it becomes a monochrome image and the fill colour of every path of the vector asset becomes #000000. How to deal with this (I am using online png to svg converter)?
-
Pedro Varela almost 4 years@LSG converting PNG to SVG it is not what you have to do. You want your SVG files created from an editor software like Adobe Illustration, Affinity Designer, etc. You have to create a vectorized version of your asset. If you don't have those skills there are a lot of options out there to find SVG assets, Google for instances has some predefine vectors that you can use in your projects material.io/resources/icons/?style=baseline. Please also read this guide. developer.android.com/studio/write/vector-asset-studio
-
LSG almost 4 years@PedroVarela I got one svg created by Adobe illustrator, but it does not work for android. It shows some error that the file is not allowed in android. Probably it goes under the limitation section. Ath this case, what should I do?
-
Pedro Varela almost 4 years@LSG that might be too many things. i am not a graphic designer nor i know the tools well. your SVG on android can't exceed 200 x 200 dp, so design for that size. I don't know what is your error so it is hard to know what is going on. you have to import your SVG into android studio, read the guides. you cannot user your raw SVG in your project. good luck.
-
Mohamed Salah over 3 yearsI'm also facing problems in Android Studio 4.0.1