0

I have several 512 x 512 icons so they are high resolution icons. I placed alle the icons under drawable-xxhdpi in my android project. The name of the icons are all correct (they start with ic_) and they are all .png

Unfortunately im unable to use the icons. When i create an imagebutton:

ImageButton imageButton = new ImageButton(this);
imageButton.setImageResource(R.drawable.ic_settings)

The project is unable to find the icon ic_settings.

So how can i add icons to my project and use them?

Mulgard
  • 9,877
  • 34
  • 129
  • 232

2 Answers2

0

pls try you get drawable by this method;

 imageButton.setImageResource(getResources().getDrawable(R.drawable.ic_settings));
raj
  • 2,088
  • 14
  • 23
  • then you have some other problem if you are creating layout in java then add image button to parent layout – raj Nov 08 '14 at 09:03
  • no. there is no other problem. images are stored under drawable. but there is no id in R.drawalbe for those images. – Mulgard Nov 08 '14 at 09:03
  • what is the location of your drawable directory is it in res/ directory – raj Nov 08 '14 at 09:05
  • yes, ofcourse it is in the res/ directory. i also cleaned the project, restarted eclipse and restarted pc. the images are still not found. – Mulgard Nov 08 '14 at 09:08
0

You need to create a new folder named "drawable" in your "res" folder and place all your icons there.

Keep the code exactly like you got it now and it will work properly.

Let me know if you need more help via comments.

Oh and to let you know why what you are doing is not working: those Drawable-hdpi, ldpi and so on refer to different screen sizes.You added your resource in xxhdpi which is the biggest screen possible.So unless you use a tablet or a virtual device that has the resolution of a tablet, it won't work.

Vlad
  • 910
  • 1
  • 10
  • 18
  • Yea, I wrote "Drawable" which is not how it's meant.I modified the answer and added an explication of why what you are doing is not working. The folder has to be named drawable -lowercase "d". – Vlad Nov 08 '14 at 09:08
  • Also -I use this sort of resources on a daily basis ,at work.It HAS to work as it is the right way to deal with "universal" kind of resources (universal meaning that the resources are not bound to a certain screen resolution) – Vlad Nov 08 '14 at 09:09
  • yes i knew that and i named it 'drawable' under the 'res/' folder. – Mulgard Nov 08 '14 at 09:10
  • I see.Is your R being created?Do you have other errors in xml / java files? It's really weird that this is not working.Even when I create an application for testing stuff that I later on use on a main application ,I create the drawable folder in res and everything works just fine. Give me some more information about this. – Vlad Nov 08 '14 at 09:13
  • Ok awesome! Happy programming^^ – Vlad Nov 08 '14 at 09:51