How to Add a Linear Gradient Background ...

How to Add a Linear Gradient Background in Android Studio

Aug 03, 2021

Hi there! In this post, I will tell you how to add a linear gradient background to an activity in android studio. The steps are listed below:

  1. Create a new file in the drawable folder called background.xml. Set the Root element to 'shape'

    image

  2. Add the following code:

    <gradient
        android:startColor="#0D973B"
        android:endColor="#1295B6" />

    The gradient element allows us to make a gradient.

  3. To add the gradient to your activity, add the background attribute in the head element. Set the value of the background attribute to "@drawable/background"

    android:background="@drawable/filename"

    image

So this is how you add a linear gradient background to an activity. If this post helped you, consider getting me some books. Bye for now.

Enjoy this post?

Buy Atharv Vishwas Gupta a book

More from Atharv Vishwas Gupta