-->

Create gradient background via XML

First, open your resources folder from your Eclipse project. Create a gradient.xml file in your drawable folder. In this gradient.xml we will define the color and the gradient. We do this by defining the start and end color and the number of degrees how the color need to change from the start value till the end value.
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">
    <gradient        android:startColor="#a0a0a0"        android:endColor="#f5f5f5"        android:angle="0"
        />
    </shape>
 Now open the layout from your activity in which you want to set this gradient background. In our case, activity_main.xml. Set the android:background=”@drawable/gradient”, in the parent view, in our case the Relative layout.

<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:background="@drawable/gradient" >

    <include        android:id="@+id/include1"        layout="@layout/actionbar" />

</RelativeLayout>

Disqus Comments