Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Table of contents
Diving deep into TextView syntax
Creating your first TextView
Creating an Android Studio Project
The main activity XML file
The main activity Kotlin file
The Android Manifest XML file
The Resources directory
Final Application
Key Takeaways
Last Updated: Mar 27, 2024

Text View in Android

Author Vasu Bansal
0 upvote
Master Python: Predicting weather forecasts
Ashwin Goyal
Product Manager @


In this blog, you will learn about the TextView widget, which is commonly used in Android applications. Understanding the concept of widgets and user interface (UI) is necessary before proceeding further in the blog. The user interface refers to the frontend or the screen with which the user interacts directly. Widgets are the elements of this user interface that helps provide a smooth interface for the users. 

Diving deep into TextView syntax

TextView is a widget that helps the developer display some text messages on the application screen. There are a lot of properties associated with TextView, such as font size, font color, themes, gravity, etc. The following is the class syntax of  TextView.

public class TextView
extends View
implements ViewTreeObserver.OnPreDrawListener

The class hierarchy of TextView is as follows.

|-> android.view.View
  |-> android.widget.TextView

There are many other widgets available in android. To learn about ListView in Android development, refer to the blog ListView on the Coding Ninjas Website.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Creating your first TextView

Creating a TextView is a simple and straightforward process. Just follow the simple steps given in below to make your first TextView.

Creating an Android Studio Project

You need to first create an Android Studio project before actually creating your Android apps. To create a new project, open up Android Studio, press the New Project button, select Empty Activity as the activity type, and select the implementation language as Kotlin. Select a minimum SDK version as per your requirements.

Don't have Android Studio and environment already set up in your machine? No worries, we got you all covered. Refer to the blog Android Studio and Environment Setup on the Coding Ninjas Website to set up things for a smoother development process.

The main activity XML file

The activity_main.xml file is the most crucial layout of your application which is referenced when we are building the interface of our application. The code for the TextView widget is written in this file. Write the following code into this file.


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

        android:text="Coding Ninjas"
        app:layout_constraintTop_toTopOf="parent" />


You can customize the attributes of this TextView by changing the values associated with the XML attributes of TextView. For example, in this case, I have assigned android:text as  Coding Ninjas and android:textStyle as bold. You can change such properties as per your requirements.

The main activity Kotlin file

This is the main file that gets your application running. This file contains the onCreate method, one of the first methods that get called after running our application. The code for MainActivity.kt file is given as below.


package com.example.textview

import android.os.Bundle

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {

The Android Manifest XML file

This file is used for registering our activities. We don’t need to change anything in this file and just use the boilerplate code provided by Android Studio for this. The code for the AndroidManifest.xml file is given below.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

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

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


The Resources directory

The resources folder named res in our Android Studio project is an important folder that contains all the resources for our application. It contains all non-coding assets of our application. For example, consider the strings.xml file present under the directory res/values. This file contains the name of the application, which is rendered when we run the application. The code of this file is written below. In this blog, we have named the application as TextView.


    <string name="app_name">TextView</string>

Final Application

The final text view that is created after following this blog will look as follows.


  1. Which attribute of the TextView is used to specify that the text type is password?
    Ans: The android:password attribute is used to specify that the text type is password. When this attribute is specified, the fields are shown as bulleted dots instead of the characters themselves.
  2. What is the use of the android:scrollHorizontally attribute in the XML file? 
    Ans: This property is used to satisfy whether the size of the text can be greater than the size of the view itself. If this attribute is set, then the text can be scrolled horizontally.
  3. Can I apply multiple text styles to the text written inside a TextView?
    Ans: Yes, you can assign multiple text styles to the text written inside a TextView with the help of the android:textStyle attribute. For example, you can apply a combination of bold and italic to a text by writing the value as bold|italic.

Key Takeaways

In this article, we have extensively discussed Text Views in Android along with a sample application containing the implementation of a sample Text View. You can also read the blog Navigation Drawer on the Coding Ninjas Website to create Navigation Drawers in your Android application.

We hope that this blog has helped you enhance your knowledge regarding Text Views and if you would like to learn more, check out our Android Development Course on the Coding Ninjas Website to learn everything you need to know about Android development. Do upvote our blog to help other ninjas grow. Happy Coding!

Previous article
Android UI Control and Types
Next article
Edit Text Widget In Android
Live masterclass