Fast ways to import drawables in Android Studio?

前端 未结 14 2141
北荒
北荒 2020-11-28 07:10

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

相关标签:
14条回答
  • 2020-11-28 07:45

    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.

    0 讨论(0)
  • 2020-11-28 07:45

    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.

    [Paste in AndriodStudio[2]

    Worked great for me.

    0 讨论(0)
  • 2020-11-28 07:46

    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. [add button within resource manager[1]

    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.

    0 讨论(0)
  • 2020-11-28 07:50

    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.

    0 讨论(0)
  • 2020-11-28 07:51

    Check android-drawable-importer-intellij-plugin

    0 讨论(0)
  • 2020-11-28 07:51

    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.

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