An Android view that can be used to sequentially animate typing and deleting one character at a time. Pausing and enqueuing arbitrary Runnables is also possible. Inspired by Devunwired @ Stackoverflow (see http://stackoverflow.com/questions/6700374/android-character-by-character-display-text-animation).
An EditText view has been used as base to get a blinking cursor. This has the drawback that the user could edit the text while it is animating. Minimum changes to the code are required to instead use a TextView as base if that is an issue.
TypewriterView typewriterView = (TypewriterView) view.findViewById(R.id.typewriter);
typewriterView.setText("Hello ");
typewriterView.pause(3000)
.type("cruel").pause()
.delete("cruel").pause(500)
.type("nice").pause()
.type(" world").pause()
.run(new Runnable() {
@Override
public void run() {
// Finalize the text if user fiddled with it during animation.
typewriterView.setText("Hello nice world");
typewriterView.setEnabled(false);
}
});
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<your.package.TypewriterView
android:id="@+id/tagline_typewriter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:textSize="16sp"
android:windowSoftInputMode="stateHidden"
android:textColor="@android:color/white"
android:text="@string/splash_tag_line_begining"/>
<!-- Overlay a view to prevent user from focusing the typewriter edit text view -->
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:editable="false"
android:focusable="false"
android:background="@android:color/transparent"></EditText>
</FrameLayout>
Probably it's a little bit late for the answer, but maybe it is useful for somebody.
You can get the length of the text already written in the typewriterView and compare it with the string you want to write.
Here, you can find an example using two strings that are declared in values/strings.xml:
if((R.string.string1).length()==typewriterView.getText().length()) {
//Finished writing text
}else{
//Text is not complete yet
}