Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

TextWriter in Android with Example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

TextWriter is used to animate text. TextWriter can be used when users open the app i.e. in place of Splash Screen. One can also use Splash Screen instead of TextWriter but TextWriter is an animation library and it is known that animations help to gain the attention of the user so it is best to learn it. TextWriter can be customized according to the requirements like textColor, textSize, letterSpacing, and many more. 
 

text-writer

 

Approach

 

  • Step 1: Add the support library in the root build.gradle file (not in module build.gradle file). This library jitpack is a novel package repository. It is made for JVM so that any library which is present in github and bitbucket can be directly used in the application. 
     

XML




allprojects {           
 repositories {           
        maven { url 'https://jitpack.io' }           
     }          
}           


  •  
  • Step 2: Add the support Library in build.gradle file and add dependency in the dependencies section. 
     

XML




implementation 'com.github.sarnavakonar:TextWriter:v1.0'          


  •  
  • Step 3: Add the following code in activity_main.xml file. In this file add the TextWriter to the layout. 
     
activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<com.sarnava.textwriter.TextWriter
    android:id="@+id/textWriter"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    />     

</androidx.constraintlayout.widget.ConstraintLayout>
  •  
  • Step 4: Add the following code in MainActivity.java file. In this file add important tags of TextWriter and also add a setListner() to it which will invoked automatically when TextWriter written the whole text.
     
MainActivity.java


package org.geeksforgeeks.textWriter          

import android.graphics.Color;
import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.sarnava.textwriter.TextWriter;

public class Activity extends AppCompatActivity {
    TextWriter textWriter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textWriter = findViewById(R.id.textWriter);   
        textWriter
                // sets the width of the view
                .setWidth(8)
                // More the value of delay,
                // more time it will take to finish
                // duration is in milliseconds
                .setDelay(30)
                // set color of text
                .setColor(Color.GREEN)
                // sets the configuration/shape of the drawing
                // based on Configuration selected
                .setConfig(TextWriter.Configuration.INTERMEDIATE)
                // set size of text
                .setSizeFactor(30f)
                // set letter spacing of text
                .setLetterSpacing(15f)
                .setText("ALGORITHM GFG")
                // when writing is finished this 
                // function will get invoked automatically.
                .setListener(new TextWriter.Listener() {
                    @Override
                    public void WritingFinished() {
                        Toast.makeText(Activity.this,
                                "Learn Algorithm!",
                                Toast.LENGTH_SHORT).show();
                    }
                })
                .startAnimation();
    }
}

  •  

My Personal Notes arrow_drop_up
Last Updated : 24 Nov, 2022
Like Article
Save Article
Similar Reads
Related Tutorials