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 t
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.
I found the easiest way is to just copy the files or in the case of a launcher icon set the folders.
And just paste them to the res folder in AndroidStudio.
[
Worked great for me.
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.
If you download your icons from https://material.io/icons/, you can use the following Bash function to import a bunch of icons in one go:
import_icons() {
project_dir=${1%/}
shift 1
for zip in "$@"; do
unzipped_dir=${zip%.*}
echo $(basename "$unzipped_dir")
unzip "$zip" -d $(dirname "$zip") >/dev/null
cp -R "$unzipped_dir"/android/* "$project_dir/app/src/main/res"
done
}
Usage example:
$ import_icons ~/Projects/MyProject ic_1.zip ic_2.zip ic_3.zip
cp -R
copies the various source mdpi
, hdpi
, etc. directories and merges them for you with the existing ones. If the directory structure of your icon package is different, just modify the first argument to cp
.
Check android-drawable-importer-intellij-plugin
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,
[ Launcher Icon, Action bar icons, Notification icons ]
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.