Gradient Background Color In Android Studio

  1. To Create Gradient Color Create A Draw able Resource File in drawable directory .

2. Add The Following Code In Your xml File And Customize Color As Your Requirement.

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:startColor="@color/application_background"
                android:endColor="@color/bright_red"
                android:angle="45"/>
        </shape>
    </item>
</selector>

Important Tips For Android Gradient Color Customization .

  1. android:startColor:
    This is the starting color of the gradient. This color will start from the top of the screen.
  2. android:endColor:
    This is the ending color of the gradient.
  3. android:centerColor:
    This color will come in the center of the screen.
  4. android:angle:
    This is a special angle and works only with the multiple of 45 including 0. So you can give 0, 45, 90, 135 and so on. Depending on the angle gradient position will change on the screen.

How to use this gradient

You can use this gradient in any layout file. below is an example.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/gradient_color">
 
    <TextView
        android:textColor="@color/white"
        android:textSize="25dp"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>

Published by

Unknown's avatar

Nusrat Faria

I Am A Web Developer And A Android Developer. This Is My Personal Blog So Noted My Work For Helping People .

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.