Android TextClock Using Kotlin With Example

Hello Readers! In this post, we are going to learn about android textClock using kotlin in any android application. We will also learn about different attributes of android textClock that can be used to customise this widget.


Tutorialwing Kotlin TextClock Output Android TextClock Using Kotlin With Example

Tutorialwing Kotlin TextClock Output

Getting Started

Android TextClock can be defined as below –

TextClock is a widget that are used to display current date and/or time in specified format.

TextClock supports 2 formats.
a. 12 hour format
b. 24 hour format.

By default, it uses 24 hour format.

Different Attributes of Android TextClock Widget

Some of the popular attributes of android textClock widget are –

Sr. XML Attributes Description
1 android:format12Hour The format in which date and/or time will be shown in 12 hour mode
2 android:format24Hour The format in which date and/or time will be shown in 24 hour mode
3 android:timeZone Defines the timezone to be used

Some of the popular attributes of android TextClock inherited from TextClock are –

Sr. XML Attributes Description
1 android:autoLink Defines whether email or mobile number is automatically detected from the text and converted to clickable links.
2 android:drawableTint Defines tint to apply to the compound drawables
3 android:gravity Defines the gravity of the view
4 android:height Defines the height of the view
5 android:maxHeight Defines maximum height of the view
6 android:minHeight Defines minimum height of the view
7 android:maxWidth Defines maximum width of the view
8 android:minWidth Defines minimum width of the view

Some of the popular attributes of android TextClock inherited from View are –

Sr. XML Attributes Description
1 android:alpha Defines alpha of the view
2 android:clickable Defines whether this view is clickable or not
3 android:id Defines id of the view
4 android:onClick Defines action to be performed when this view is clickable
5 android:padding Defines padding to apply this view
6 android:visibility Defines visibility of the view

Example of Android TextClock Using Kotlin

At first, we will create android application. Then, we will use textClock using kotlin in the application.

1. Creating New Project in Kotlin

Follow steps below to create new project. Please ignore the steps if you have already created the project.

Step Description
1. Open Android Studio.
2. Go to File => New => New Project. Write application name as TextClock. Then, check Include Kotlin Support and click next button.
3. Select minimum SDK you need. However, we have selected 17 as minimum SDK. Then, click next button
4. Then, select Empty Activity => click next => click finish.
5. You will get a newly created project successfully if you have followed steps properly.

Since we have a project now, we will modify xml and other files to use textClock using kotlin in the application.

2. Modify values folder

No values folders have been modified. So, we are not going to mention them here.

3. Use TextClock Widget in xml file

Open src/main/res/layout/activity_main.xml file and add below code into it.

<?xml version="1.0" encoding="utf-8"?>

		android:format12Hour="hh:mm:ss a"/>


In activity_main.xml file, we have defined textClock widget. Attribute android:format12Hour is being used to specify the format for 12 hour format of the textClock.

4. Access TextClock Widget in Kotlin file

Open src/main/java/com.tutorialwing.textclock/MainActivity.kt file and add below code into it.

package com.tutorialwing.textclock

import android.os.Bundle

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

We have not changed anything in MainActivity.kt file.

Since AndroidManifest.xml file is very important in any android application, we are also going to see the content inside this file.

AndroidManifest.xml file

Code inside main/AndroidManifest.xml file is as below.

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.tutorialwing.textclock"

		<activity android:name=".MainActivity">
				<action android:name="android.intent.action.MAIN"/>

				<category android:name="android.intent.category.LAUNCHER"/>


When we run the program, we will get output as shown above.

That’s end of our tutorial on Android textClock using Kotlin.