By Alvin Alexander. Last updated: August 3, 2017
When you need to reference a drawable image from an Android XML file, such as a layout or menu file, use this tag:
android:src="@drawable/myimage"
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:
<item android:id="@+id/menu_item_control_images" android:icon="@drawable/images_show" android:title="@string/menu_hide_images" myapp:showAsAction="ifRoom" />
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 Android.com Drawable Resources page.