Android: How to reference a drawable image in XML (or Java)

When you need to reference a drawable image from an Android XML file, such as a layout or menu file, use this tag:


That assumes that you have a file named myimage.png in your res/drawable directories. As a more complete example, this shows how I reference an image named images_show.png in an Android menu item:


In your Android/Java source code you can also refer to that same image like this:

Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.myimage);

For more information, see the Drawable Resources page.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.