0

I'm working on an application that deals with getting an image from the drawable folder. In one of my last application what I did was I created a different ic_abc folders for each icon in my application and in there, there would be same image with different sizes in each of them. I was using these icons in the menu folder in that application.

Now in this application I don't know why but I can't access my drawable assets directly from the activity like R.id.imagename or R.drawable.imagename

Any ideas why is it acting like this?

enter image description here

Dave2e
  • 22,192
  • 18
  • 42
  • 50
Sagar
  • 416
  • 7
  • 23

1 Answers1

1

The resource system currently does not support sub folders in your drawable folders. However, the different sizes of icons will be automatically arranged in appropriate subfolders by Android Studio if you do it properly.

You will need the following setup:

res
-- drawable
-- drawable-mdpi
-- drawable-hdpi
-- drawable-xhdpi
etc..

Then when you put your icon sizes in each of these folders, Android Studio will map them under one folder that has the same name as your icon.

The reason why you can't reference the files in your subfolders trough the R file is because the compiler will ignore any files in a subfolder, therefor it doesn't add the reference to the R.java file.

Tim Kranen
  • 4,202
  • 4
  • 26
  • 49
  • This works however my another working project has folders for each file containing same picture in different sizes and it works completely fine. Any idea why? – Sagar Jul 08 '16 at 20:32
  • @Sagar Are you sure that Android Studio didn't create those folders? How are you referencing those pictures? It works, but you just can't reference the R.java file (so no R.id....) – Tim Kranen Jul 08 '16 at 21:35
  • For that separate folders for each file i was referencing them in the menu xml like android:icon="@drawable/ic_delete" – Sagar Jul 08 '16 at 21:38
  • And in that case ic_delete was in a subfolder? – Tim Kranen Jul 08 '16 at 21:46
  • yes , I had one folder for each one of my icons like ic_delete , ic_share. and each one of these folders have four files of their respective images of four sizes – Sagar Jul 08 '16 at 22:02
  • The only thing I can think of is that the @drawable/.. doesn't use the R file to reference its documents, that might be the reason why it is working in that case. – Tim Kranen Jul 08 '16 at 22:14
  • Yeah possibly. Anyways Thanks for your solution. Cheers :) – Sagar Jul 09 '16 at 22:29