user1302569
user1302569

Reputation: 7191

Gradient Color in layout in android

I would like to know how I can set gradient color in my layout. I want to start with dark green from left side and become lighter to center and from center to right that color should be become darker. How I can do that?

Upvotes: 1

Views: 946

Answers (2)

Chirag
Chirag

Reputation: 56925

Create one selector file and put in drawable folder.

<?xml version="1.0" encoding="utf-8"?>
    <shape>
        <gradient
            android:angle="90"
            android:startColor="#FFFF0000"
            android:centerColor="#0000FFFF" 
            android:endColor="#FF00FF00"
            android:type="linear" />
    </shape>

Change color as per your requirement. Change angel as per your requirement also.

Look Here for more details.Choose Your Green Color code from here . http://www.december.com/html/spec/color2.html

Upvotes: 5

Aerilys
Aerilys

Reputation: 1629

You have to create a shape drawable as specified here:

http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

Here is an example:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <gradient
        android:angle="90"
        android:endColor="#000"
        android:startColor="#fff"
        android:type="linear/>
</shape>

Upvotes: 3

Related Questions