热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在AndroidStudio中快速导入可绘制文件的方法?-FastwaystoimportdrawablesinAndroidStudio?

AtsomepointinanAndroidprojectyouwillneedtoimportsomedrawables-beittoolbaricons,im

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, ...).

在Android项目的某个时候,您将需要在res/drawable目录中导入一些可绘制的内容——无论是工具栏图标、图像还是UI特性。大多数情况下,您将图像缩放为最常见的限定符(draw- hdpi、draw- mdpi、draw- xdpi、draw- 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?

如果你要导入多个图片,那就太烦人了。是否有一种简单、快速的方法来传输这四个文件实例?在相应的包文件夹中的png ?IDE中实现了什么功能?一些简单的解决方案?

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;
  • 复制/粘贴操作系统文件管理器,从外部目录到包,然后刷新Android Studio中的资源文件。这意味着打开每个限定子目录,因此有四个动作;
  • from the OS file manager, move to external_dir, search for file.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, and Paste in the corresponding package directory. Not really better!
  • 从OS文件管理器移动到external_dir,搜索文件。png,将四个实例放在一个列表中,拖放到Android Studio中,然后在导航条上右键单击,复制并粘贴到相应的包目录中。不是更好!

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).

编辑——当然,我并不是真的想要“建议”——我想知道是否有一种方法可以将移动的次数减少到一个(或类似的)。

10 个解决方案

#1


48  

Check android-drawable-importer-intellij-plugin

检查android-drawable-importer-intellij-plugin

#2


16  

My Answer on Jan 16, 2017.

我的答案是2017年1月16日。

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.

两年后,Android Studio有了导入图像资产的方法。但是我想添加一个新的评论。Android现在支持向量,所以我们不必担心不同的分辨率。我建议使用矢量图和矢量图。

Just right click your app name in the Project -> New -> Vector Asset.

只需右键单击项目中的app名称——>新->矢量资产。

Just follow the wizard.

跟着向导。

Best regards, Pedro.

最好的问候,佩德罗。

My Answer on Feb 18, 2015.

我的答案是2015年2月18日。

If I don't misunderstood, this is what I do in my Android Studio (AS) projects.

如果我没有误解,这就是我在我的Android Studio (AS)项目中所做的。

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.

我发现我们只需要导入最高分辨率的资源;这也会影响到你。我要求我的设计师只生成xxhdpi文件,然后。

You go to your /res folder in the Project navigator, right click and select New -> Image Asset

进入项目导航器中的/res文件夹,右键单击并选择New ->图像资产

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。

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.

最好,佩德罗。

#3


12  

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.

正如Rob Meeuwisse在上面的评论中提到的,您可以在一个副本中完成,然后粘贴操作。而不是复制粘贴的每个文件,您可以选择四个drawable-XXXX文件夹(而不是图像本身!)在你的操作系统的文件管理器在同一时间(按ctrl - click在Windows / Linux或Command-clicking OS X),复制所有这些文件夹,然后粘贴到res文件夹在Android工作室。

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.

图片将自动粘贴到适当的可拉的文件夹在研究》这个作品,因为如果Android工作室注意到你复制粘贴一个文件夹已经存在的项目,它会使用现有的文件夹和粘贴的失踪而不是取代/丢弃的文件已经存在。

#4


2  

With Mac OS X Finder you can simply copy/paste the folders drawable-mdpi, drawable-hdpi, drawable-xdpi, drawable-xxdpi in a single move to my_package/ and then select the option Merge in the appearing Finder dialog. This will add the new files to the corresponding folders in my_package/.

使用Mac OS X查找程序,您可以简单地将文件夹draw- mdpi、draw- hdpi、draw- xdpi、draw- xxdpi复制/粘贴到my_package/,然后在appearance Finder对话框中选择Merge选项。这将向my_package/中的相应文件夹添加新文件。

However, note that this is only possible if the source and target folders do not contain any identically named files.

但是,请注意,这只有在源文件夹和目标文件夹中不包含任何名称相同的文件时才可能实现。

#5


2  

  1. Select the "res" directory
  2. 选择“res”目录
  3. Right click and select "Compare with"
  4. 右击并选择“与…比较”
  5. Find the directory where your drawables are coming from
  6. 找到您的可绘制文件来自的目录
  7. Hide outgoing changes
  8. 隐藏即将离任的变化
  9. Select all the incoming changes and click the arrow to synchronize.
  10. 选择所有传入的更改并单击箭头进行同步。

#6


1  

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!

我通常用一个非常简单的方法:我使用这个工具来生成图像直接在正确的文件夹的名字:你只需要打开工具,阻力更大的图像(例如:一个您想要使用xhdpi文件夹或者xxhdpi文件夹):这个工具将创建原始图像的文件夹所有其他文件夹(ldpi mdpi,hdpi等)包含图像的适当比例。一旦你有了这个文件夹,你只需将它们粘贴到res文件夹中,完成!

#7


0  

In your Android Studio, Right click drawable -> New -> Image Asset -> Asset Type: Action Bar and Tab Icons. Image file: image_path, Resource Name: image name -> Next -> Finish

在您的Android Studio中,右击drawable -> New -> Image Asset -> Asset Type: Action Bar and Tab图标。图像文件:image_path,资源名:Image Name -> Next -> Finish。

Done

完成

This will add 4 different sizes of your image so that it will fit depending the device size

这将增加4种不同大小的图像,使它将适合不同的设备大小

#8


0  

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:

如果你从https://material下载图标。io/图标/,您可以使用下面的Bash函数一次导入一堆图标:

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.

cp -R复制各种源mdpi、hdpi等目录,并将它们与现有目录合并。如果图标包的目录结构不同,只需将第一个参数修改为cp。

#9


0  

It seem the way to do it is drag and dropping the resources to AS. For instance. We have a bunch of images, we grab all the xxhdpi images drop them in AS and then it will ask you which resolution are those images, so we choose from the pouup xxhdpi.. then, all the images in xhdpi drop again choose xhdpi from pop up, and that's the way to import assets to A.S. and so on with each resolution.

这样做的方法似乎是将资源拖放到AS中。例如。我们有一堆图像,我们把所有的xxhdpi图像都放进去然后它会问你哪些分辨率是这些图像,所以我们从pouup xxhdpi中选择。然后,xhdpi中的所有图像都再次从弹出中选择xhdpi,这是将资产导入到A.S.等的方法。

#10


0  

Simplest and Fastest way is just copy paste all in one shot only if you have image in already formatted folder as mentioned below.

最简单和最快的方法是,只要你在已经格式化过的文件夹中有图片,你就可以复制粘贴。

  • Download any image from Meterial Icons here

    从这里的入口图标下载任何图片

  • Downloaded folder contains all levels of drawable folders (mdpi, hdpi, ect..)

    下载文件夹包含所有级别的可拖动文件夹(mdpi、hdpi等)

  • Just copy all the folders and paste it to res folder, Here the folder is not replacing just the new image will going to add existing image.

    复制所有文件夹并将其粘贴到res文件夹中,这里的文件夹并不只是替换新映像将添加现有映像。


推荐阅读
author-avatar
我俩的12月11_484
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有