简体   繁体   English

将图像放在drawable文件夹中?

[英]Put image in drawable folder?

I put an image in my res/drawable folder, but when I clean and build my project, I receive the error message R cannot be resolved . 我在我的res / drawable文件夹中放了一个图像,但是当我清理并构建我的项目时,我收到错误消息R cannot be resolved I don't understand why this happens, what should I do? 我不明白为什么会这样,我该怎么办?

Check out the following link: http://source.android.com/source/using-eclipse.html 请查看以下链接: http//source.android.com/source/using-eclipse.html

Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask eclipse to sort or otherwise manage imports. 注意:Eclipse有时喜欢在使用资源的文件顶部添加“import android.R”语句,尤其是当您要求eclipse对排序或以其他方式管理导入时。 This will cause your make to break. 这会导致你的品牌破产。 Look out for these erroneous import statements and delete them. 注意这些错误的import语句并删除它们。

After removing the erroneous imports, delete your R.java file and try to clean and build the project again. 删除错误的导入后,删除您的R.java文件并尝试再次清理和构建项目。 If the problem still persists, post here. 如果问题仍然存在,请在此处发布。

possible causes: 可能的原因:

  1. duplicate file names (across all drawables folders) . 重复的文件名(跨所有drawables文件夹)。 for example , is there a file named "h1.png" and also "h1.jpg" ? 例如,是否有一个名为“h1.png”和“h1.jpg”的文件?

  2. bad files names . 坏文件名。 only letters allowed are lowercase english ones , and digits. 只允许使用小写英文和数字。

  3. hidden files , like those of the OS . 隐藏文件,如操作系统的文件。 on windows , it's probably "Thumb.db" . 在Windows上,它可能是“Thumb.db”。 either delete them , or delete & disable them. 要么删除它们,要么删除和禁用它们。 linux and mac also have such files , but with different names and usually start with "." linux和mac也有这样的文件,但名称不同,通常以“。”开头。 .

确保您的图像名称位于较小的 latter和res / drawable文件夹中。有关我们如何在项目中添加drawable和支持的图像格式,请参阅docs Drawable Resources

Might be you are using android.R.drawable.your_image 你可能正在使用android.R.drawable.your_image

Remove android.R from imports. 从导入中删除android.R。 use R.drawable.your_image 使用R.drawable.your_image

For Android Studio : 对于Android Studio

  1. Right click on res, new Image Asset 右键单击res,新的Image Asset
  2. On Asset type choose Action Bar and Tab Icons 资产类型上,选择操作栏和选项卡图标
  3. Choose the image path 选择图像路径
  4. Give your image a name in Resource name 在资源名称中为您的图像命名
  5. Next->Finish 下一步 - >完成

The image will be saved in the /res/drawable folder! 图像将保存在/ res / drawable文件夹中!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM