How do you define gradient color in Android?

January 31, 2012

Answer
In order to define a gradient that can be used in your app, define it an 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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android">
  3.     <gradient
  4.         android:startColor="@color/White"
  5.         android:endColor="@color/Black"
  6.         android:angle="30"/>
  7. </shape>
Android MediaPlayer Source CodeHow do you define colors to be used in layouts in an Android App?
Sponsors
Like us on Facebook