Issue
I wanted add a PNG image file to my app. I try to drag and drop the file from Windows File Explorer to the drawable directory note of Android Studio, but it did not work. There is an Add Image Asset dialogue, but it was way more complicated for such as simple task. And if there are multiple different image to add, using this dialogue will be very annoying.
Android API Guide says PNG images can be put in the drawable directory, and the file name will be the resource ID. So, I just opened the drawable directory with File Explorer and copied the image file into the directory. Then, Android Studio shows the image file under the drawable node, but the file name was in red color unlike other green files. As expected, there was no resource ID for the red PNG file.
If this were Visual Studio, I would right-click the PNG image and set its build behaviour as embedded resource. But I could not find such menu in Android Studio. Is the Add Image Asset the only way?
Solution
If this were Visual Studio, I would right-click the PNG image and set its build behaviour as embedded resource
Such a step is not required and it simply discover all resources in the correct folder. You can just drop them in the correct folder outside Android Studio.
However a clean is a good idea if you are not seeing the new resource id.
Note also that mipmaps are accessed by R.mipmap.
not R.drawable.
.
Look here for correct folder structure and location: http://developer.android.com/guide/topics/resources/providing-resources.html
Answered By - weston
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.