Skip to content
Related Articles

Related Articles

How to Create Star Animation in Android?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 18 Apr, 2021

In this article, we are going to create star animation using an animated-star library. Here we will be creating a background drawable file and will specify the color for the animation. The star animation we have created is easy to create since we are using a library. A sample GIF is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Kotlin language. 

Create Star Animation in Android Sample GIF

Step by Step Implementation

Step 1: Create a new Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.  

Step 2: Add dependency and JitPack Repository

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.   

implementation ‘com.sofakingforever.libraries:animated-stars-android:1.1.4@aar’

Add the JitPack repository to your build file. Add it to your root build.gradle at the end of repositories inside the allprojects{ } section.

allprojects {

 repositories {


   maven { url “” }



After adding this dependency sync your project and now we will move towards its implementation.  

Step 3: Working with the colors.xml file

<?xml version="1.0" encoding="utf-8"?>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="star_color_1">#ffffff</color>
    <color name="star_color_2">#25Adff</color>
    <color name="star_color_3">#FFC100</color>
    <color name="star_color_4">#FF3800</color>


Step 4: Working with the array.xml file

Create an array.xml file in the values folder. Right-Click, then click on New > Values Resources File and then create a file with a name array.

<?xml version="1.0" encoding="utf-8"?>
    <integer-array name="star_colors">
        <!-- This is how you can configure the ratio of star colors-->
    <integer-array name="meteorites_colors">

Step 5: Working with the background.xml file. Create this for adding in the background.


<?xml version="1.0" encoding="utf-8"?>
        android:type="linear" />

Step 6: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
        app:starsView_starCount="50" />

Step 7: Working with the MainActivity.kt file

Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
    override fun onStart() {
    override fun onStop() {


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!