Android TextSwitcher

Android TextSwitcher

A TextSwitcher is a specialized ViewSwitcher that contains only children of type TextView. A TextSwitcher is useful to animate a label on screen. Whenever setText(CharSequence) is called, TextSwitcher animates the current text out and animates the new text in.

To learn Basic of Android Animation  go to  Android Animation Tutorial.

Two types animations are required for  for TextSwitcher to switch between the texts.
1: In Animation: with which  Text come in the Screen.
2: Out Animation: with which Text goes out from the Screen.

Example

In this example i will demonstrate you how to work switch between the TextViews.

VIDEO DEMO

Let’s get start by creating a project in Eclipse IDE.

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as MainActivity.java)

2.  Create a layout file for MainActivtiy.java under res ⇒ layout folder. I named the layout file as activity_main.xml. In this layout i had taken TextSwitcher for switching between texts and a Button to show the next Text.

3. Now, add the following code to MainActivity.java , in this activity i am going to show how to switch between the Text. You can add as much Text for switching.

4. Finally, run the app and you will get the output as shown in video.

Thanks. :)

Download Source Code – >

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)