Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android string animation

public class Typewriter extends TextView {

    private CharSequence mText;
    private int mIndex;
    private long mDelay = 500; //Default 500ms delay


    public Typewriter(Context context) {
        super(context);
    }

    public Typewriter(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private Handler mHandler = new Handler();
    private Runnable characterAdder = new Runnable() {
        @Override
        public void run() {
            setText(mText.subSequence(0, mIndex++));
            if(mIndex <= mText.length()) {
                mHandler.postDelayed(characterAdder, mDelay);
            }
        }
    };

    public void animateText(CharSequence text) {
        mText = text;
        mIndex = 0;

        setText("");
        mHandler.removeCallbacks(characterAdder);
        mHandler.postDelayed(characterAdder, mDelay);
    }

    public void setCharacterDelay(long millis) {
        mDelay = millis;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: test excel file java multipart 
Java :: java application security best practices 
Java :: @exceptionhandler spring boot annotation not found 
Java :: how to preset an array java 
Java :: how to know what a valid name for a variable is in java 
Java :: java lambda expression in priorityqueue 
Java :: cellrangeaddress in set border example in java 
Java :: Java @SuppressWarnings Annotation Example 
Java :: which exception is thrown when java is out of memory 
Java :: Java Protected Access Modifier package two 
Java :: h2 database allow remote database creation 
Java :: jfxsa-run-no-another-jvm java fxml error 
Java :: java scanner equation 
Java :: java code to get all leaf nodes of a xml file 
Java :: closable resources java 
Java :: exception in thread "main" java.lang.arrayindexoutofboundsexception: 10 
Java :: sha 1 key throguh java is not working 
Java :: add elements to arraylist of arraylist in java 
Java :: lmethod java 
Java :: java calculator joptionpane 
Java :: multi threading callable 
Java :: write a code to print second last word of input string 
Java :: open application programelly android studio 
Java :: convert from java to kotlin online 
Java :: error message pushes button down 
Java :: java list to jsonelement 
Java :: how to know when user is done typing android 
Java :: java switch case enum 
Java :: java instanciar objeto File 
Java :: Uri/Beecrowd problem no 1180 solution in JAVA 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =