Creating color changing background in Android

Updated 13 May 2019

Save

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.

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • krishna yarlagadda
    • Vedesh Kumar (Moderator)
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home