0

Trying to figure out how to make a gradient color on very light gray to "almost white". As an example I can refer to ebuddy for android. Your "buddies" are in a list which is of a gradient color.

How is this done in android? I believe it should be using aarrggbb right?

user848106
  • 235
  • 1
  • 8
  • 18
  • I believe you have to use a drawable as the background. Check this [question](http://stackoverflow.com/questions/2928101/android-using-linear-gradient-as-background-looks-banded) for more details – tsukimi Jun 19 '12 at 03:47
  • Check this link - [Shape Drawable](http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape) – Shaiful Jun 19 '12 at 04:04

2 Answers2

2

You can make GradientDrawables to create Gradients into android, for example:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
  <gradient
      android:startColor="#FF808080"
      android:endColor="#FFFFFFFF"
      android:angle="270"/>
</shape>
jeet
  • 29,001
  • 6
  • 52
  • 53
0

You can create this rectangle.xml file in the drawable folder in res folder:(Here colors are exactly how you want)

  <?xml version="1.0" encoding="UTF-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="rectangle"  type="rectangle">

  <gradient android:angle="90" android:startColor="#a3a3a3" android:centerColor="#cfcfcf" android:endColor="#f0f0f0"/>

now you can use it as a background of your screen by defining it in the style.xml file like this:

    <style name="screenBackground">
        <item name="android:paddingLeft">5dip</item>
        <item name="android:paddingTop">2dip</item>
        <item name="android:paddingRight">5dip</item>
        <item name="android:paddingBottom">2dip</item>
        <item name="android:background">@drawable/rectangle</item>
        <item name="android:layout_marginBottom">15dp</item>
    </style>

Now use it in your main.xml file :

   <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout android:id="@+id/header"
      android:layout_width="fill_parent" android:layout_height="wrap_content"
      xmlns:android="http://schemas.android.com/apk/res/android" style="@style/screenBackground">

       // All your other elements in the xml file go here.

     </LinearLayout>
Yogesh Somani
  • 2,624
  • 3
  • 21
  • 34