Creating color changing background in Android

Recently we have seen that Instagram has introduced an eye-catching color changing background of the login page in their iOS version of the application. The page’s background keeps changing colors like a gradient which looks really amazing. There are some libraries available on the internet which can create the same effect for you but in this blog, we will learn how this can be done without any libraries.

What we are going to do.

  1. Create some drawable files with different color gradients.
  2. Create another drawable with animation-list tag and add all the created gradient drawables as the items.
  3. Use the animation-list drawable as the background of the view.
  4. Start the animation in the onCreate method of the Activity of the fragment.

Let us see the steps in detail and with some code snippets.

1) Creating drawable files

Create some drawables files which contain gradients. For example:

-> gradient_1.xml

-> gradient_2.xml

2) Create an animation-list drawable

Create background.xml drawable inside it we will define the items and set the gradient_1 and gradient_2 files as drawables.

3) Using animation-list drawable

You can use the background.xml as the background a view.

4) Start the animation

In your activity or fragment, you will have to start the animation and this can be done in your onCreate method.

On starting the animation it will start the transition between the gradient and it looks really cool.

Thank you very much. This is Vedesh Kumar signing off.

. . .

Comments (2)

Add Your Comment

  • krishna yarlagadda
    thank you very much for this gradient background
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close