Set complete layout background color in android xml

Apply any color as per app user requirement on linear , relative , Grid, frame, table,fragment layouts using xml.

All layout background color can be easily changeable through main activity.xml file by using simple android:background=” ” attribute in layout tag. On the double course you have to define #color code. So here is the step by step tutorial for Set complete layout background color in android xml.

android-project-download-code-button

How to Set complete layout background color in android xml.

Code for MainActivity.java file.

package com.android_examples.com.layoutbackgroundcolorxml;
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.layoutbackgroundcolorxml.MainActivity"
 android:background="#64d8fe" >

 <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 Color changed via layout xml file "
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:textColor="#fafafa" />

</RelativeLayout>

Screenshot:

Set complete layout background color in android xml

Click Here To Download Set complete layout background color in android xml project.

Leave a Reply

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