Android TextSwitcher is a user interface widget that contains number of textView and displays one at a time. Textswitcher is subclass of View Switcher which is used to animates one text and displays next one.
Here, we create TextSwitcher programmatically in Kotlin file.
First we create a new project by following the below steps:
- Click on File, then New => New Project.
- After that include the Kotlin support and click on next.
- Select the minimum SDK as per convenience and click next button.
- Then select the Empty activity => next => finish.
Modify activity_main.xml file
In this file, we use the TextSwitcher, Buttons and also set their attributes.
Update strings.xml file
Here, we update the name of the application using the string tag.
Create TextSwitcher in MainActivity.kt file
First, we declare an array languages which contains the list of languages used for the textView.
private val textList = arrayOf("Java","Python","Kotlin","Scala","C++")
then, we create the TextSwitcher and set attributes for textView like text color, text Size.
val textSwitcher = findViewById<TextSwitcher>(R.id.textSwitcher)
Add the TextSwitcher in layout using this
val c_Layout = findViewById
(R.id.constraint_layout) //add textSwitcher in constraint layout c_Layout?.addView(textSwitcher)
Run as Emulator:
Click prev button then we obtain the other text in the TextView.
- TextSwitcher in Kotlin
- Dynamic EditText in Kotlin
- Dynamic ScrollView in Kotlin
- Dynamic Button in Kotlin
- Dynamic TimePicker in Kotlin
- Dynamic RatingBar in Kotlin
- Dynamic AutoCompleteTextView in Kotlin
- Dynamic ImageButton in Kotlin
- Dynamic DatePicker in Kotlin
- Dynamic RadioGroup in Kotlin
- Dynamic Switch in Kotlin
- Dynamic SeekBar in Kotlin
- Dynamic CheckedTextView in Kotlin
- Dynamic ProgressBar in Kotlin
- Dynamic ToggleButton in Kotlin
- Dynamic ImageSwitcher in Kotlin
- Dynamic Chronometer in Kotlin
- Dynamic RadioButton in Kotlin
- Dynamic Spinner in Kotlin
- Dynamic TextView in Kotlin
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.