简体   繁体   English

如何在Android的res文件夹中添加图像

[英]How to add images in res folder in android

I am trying to add some images to res folder in my android 4.2.2 application. 我正在尝试将一些图像添加到我的android 4.2.2应用程序的res文件夹中。 The problem is the project runs fine until whenever I do add, upon running it gives an error 问题是项目运行正常,直到我每次添加时,运行时都会出现错误

R cannot be resolved to a variable

in the src/MainActiviy.java and the R.java file deletes it self from the gen folder. src/MainActiviy.java ,并且R.java文件从gen文件夹中将其自身删除。

Now I'm naming the folder drawable-mdp and every png image is also lower cased. 现在,我为文件夹drawable-mdp命名,每个png图像也都小写。 But it doesn't seem to bother. 但这似乎并不麻烦。 Thanks! 谢谢!

You are getting this error because R.java failed to create. 您收到此错误,因为R.java创建失败。 This happens when you try to a non-png image or the name of image contains some special character or characters in uppercase. 当您尝试使用非png图像或图像名称包含一些特殊字符或大写字符时,会发生这种情况。

Ok guys I did try a few things and I finally got it. 好的,我确实尝试了几件事,终于知道了。 You can't use - hyphen while naming the image files themselves however _ underscore can be used. 您不能在命名图像文件本身时使用-连字符,但是可以使用_下划线。 Note you always have to use drawable- while naming the folder can't use _ underscore 请注意,您始终必须使用drawable-,同时命名文件夹时不能使用_下划线

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

相关问题 如何将菜单文件夹添加到android studio项目的res文件夹中 - How to add a menu folder to the res folder of an android studio project 数组适配器从Res文件夹加载图像(Android应用程序) - Array Adapter Load Images from Res Folder (Android App) 无法在Android Studio中将版本Qualifier Folder添加到res / menu - Cant add version Qualifier Folder into res/menu in Android Studio 如何在 Android Studio 中查看 res/drawable-nodpi/ 文件夹 - How to see res/drawable-nodpi/ folder in Android Studio 如何正确地将图像检索到Android项目的res / drawable /文件夹中? - How correctly retrieve an image into the res/drawable/ folder of an Android project? 如何将图像保存在特定的Android文件夹中 - How to Save images in an specific folder android 加载图像时,在Java中是否仍需要'res'类文件夹? - Is a 'res' class folder still necessary in Java when loading images? 如何访问res / raw文件夹或android中任何其他位置的文件? - How can I access files in res/raw folder or any other location in android? 如何在res / layout文件夹下的.xml文件中使用伪代码? 安卓系统 - How to use Pseudo Code in a .xml file under res/layout folder? Android 如何使用res文件夹代替sdcard - How to use res folder instead sdcard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM