In order to define a gradient that can be used in your app, define it a resource file.


e.g. the resource file can be named as gradient.xml in the res/drawables directory of your project as:

res/drawables/gradient.xml
<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:startColor="@color/White"
            android:endColor="@color/Black"
            android:angle="30"/>
    </shape>

The above snippet defines a gradient which start with a white color and ends with a black one at an angle of 30.