Set background image in whole layout android xml

Add drawable image as background in layout so it creates complete activity app background.

android-project-download-code-button

Images can also be set as background in complete layout so when your apps open then it will show selected inserted image as app activity background. Images can be call through Drawable folder so and developer can manually copy all images there. So here is the complete step by step tutorial for Set background image in whole layout android xml.

Note: First copy background image in res-> drawable-hdpi folder.

drawable hdpi folder

How to Set background image in whole layout android xml.

Code for MainActivity.java file.

package com.android_examples.com.layoutbackgroundimage;
import android.app.Activity;
import android.os.Bundle;


public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.layoutbackgroundimage.MainActivity"
 android:background="@drawable/background_image" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Layout background image set via activity_main.xml file"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:textColor="#fbf8f9" />

</RelativeLayout>

Screenshot:

Set background image in whole layout android xml

Click Here To Download Set background image in whole layout android xml project.

One Comment

  1. that was really helpfull thank u

Leave a Reply

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