By default Android doesn’t provide a simple way to add the glow to the text view or any other view, so to make our app more attractive and beautiful we can add the glow effect to our TextView. In order to do so, we can use many different external libraries. 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 Java language.
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 Java as the programming language.
Step 2: Before going to the coding section first do some pre-task
Go to app -> res -> values -> colors.xml file and set the colors for the app.
Go to Gradle Scripts > build.gradle (Module: app) section and import the following dependencies and click the “sync Now” on the above pop-up.
// Adding glowtextview
Step 3: Designing the UI
In the activity_main.xml remove the default Text View and change the layout to Relative layout and add the GlowTextView and we also add 2 SeekBar to change the color and radius of the glow text view as shown below. Below is the code for the activity_main.xml file.
- app:glowRadius: it is used to set the glow Radius [ default value 60f ]
- app:glowColor: it is used to set the glow Color [ default color value WHITE ]
Step 4: Coding Part
Open the MainActivity.java file and inside the class, we create an array of integer to store different colors ( which we use later to change the color of the GlowTextView ) as shown below
Now inside the onCreate() get the reference of the GlowTextView and 2 SeekBar and set the max of the color SeekBar to the colors.length – 1 as shown below.
Now create a SeekBarChangeListener of both the SeekBar and inside the onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) set the GlowColor and GlowRadius value to the process as shown below
Below is the complete code of the MainActvity.java file.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.