Gradient dividers


SDK Version: 
M3

Today I’m going to show you an easy way to create gradient backgrounds in your applications.

Create an xml file in drawable directory and modify like this:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3.         android:shape="rectangle">
  4.         <gradient
  5.          android:startColor="#FF0000"
  6.          android:endColor="#00FF00"
  7.          android:angle="90" />
  8. </shape>

This code snippet generate a divider with gradients that fade from green to red.

After that you can use that such a drawable for layout background.

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:orientation="vertical"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     android:background="@drawable/gradientcolors">
  7.  
  8. </LinearLayout>

Learn more about Gradient drawable here.