Displaying a background image in Android

Goto your res folder as shown in image below add a background image.

After adding a background image, goto the main.xml and add the below text:
android:src=”@drawable/background” />
Note: Do not add the extn to the image name, it wont recognize the file and give an error.
Next goto your main class and add the following:
// Set the background
Another way to do this would be:
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.background);

Leave a Reply

Your email address will not be published. Required fields are marked *