Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: R.drawable not showing my image?

In my android 2.2 app, I've added my image to the res/drawable-mdpi folder. However, I cannot seem to access it using R.drawable.. As far as I know, there isn't any additional configuration I need to do - any help?

like image 796
Andy Hin Avatar asked May 01 '11 02:05

Andy Hin


People also ask

How do I insert a picture into a drawable file?

To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.


2 Answers

I figured this out. The issue was that the project was importing android.R instead of using the generated R file - if you encounter this problem, check your imports to make sure the correct package/file is being imported.

like image 124
Andy Hin Avatar answered Sep 19 '22 22:09

Andy Hin


You need to use a fully qualified name when importing the generated R file. Check your import statements.

Take the following package statement:

package me.rhys.example;

Then the generated R file can be imported using:

import me.rhys.example.R;
like image 29
Rhys Avatar answered Sep 19 '22 22:09

Rhys