Android TextView and setText Dynamically example in Kotlin

Android TextView is a user interface element show text (label) to users in the application. You can change TextView dynamically (programmatically). View class is the parent class of android.widget.TextViewTextView can Create by declaring it inside a layout XML file or by instantiating it programmatically.

Android TextView and setText Dynamically example in Kotlin

Android TextView Attributes

Here we are explaining the some attribute of TextView.


This is the ID which uniquely identifies the control.


android TextView textAllCaps

Set all the text in ALL CAPS.


android TextView set color

Set the Text color of TextView widget android.


android TextView set text size

Set the Size of the text, use SP unit to set size.


Style (normal, bold, italic, bold|italic) for the TextView Android

Style (normal, bold, italic, bold|italic) for the TextView.

For more you can check Android official documentation of complete list of attributes and related methods, Uses to change these attributes are run time or make as per app requirements.

Lets Build a Complete Example of Android TextView:

In this example will learn change TextView dynamically, change color , setText , change Text Size, Change style and Capitalize TextView.

Step 1. Create new project “Build Your First Android App in Kotlin
Step 2. Add the following code in “activity_main.xml” resource file
Step 3. Open the “MainActivity.kt” and add following code 

Here Button have even on click event , where TextView is changing text dynamically.

Step 4. Now Run the application, in emulator or On you android device
Output screenshot Android TexView example :
Android TextView and setText Dynamically example in Kotlin output all

Download source code Android TextView in kotlin

Note: This example (Project) is developed in Android Studio 3.1.3. Tested on Android 9 ( Android-P), compile SDK version API 26: Android 8.0 (Oreo)



Coding in Kotlin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.