Android Checked TextView

CheckedTextView can be defined as below –

"CheckedTextView is an extension of TextView that supports the checkable interface and displays it. It has a checkbox along with some text. It is mainly used in a ListView where we want to show which item is selected or not. The checkmark attribute is used to provide a graph or a drawable to CheckedTextView."

Generally, it is used in ListView where setChoiceMode was set to something other than CHOICE_MODE_NONE.





Some of the popular attributes of android CheckedTextView widget are –

S. No. XML Attributes Description
1 android:checked Indicates the initial checked state of this text.
2 android:checkMark Drawable used for check mark graphic.
3 android:checkMarkTint Tint to apply to the check mark.
4 android:checkMarkTintMode Blending mode used to apply the check mark tint.

Attributes of Android CheckedTextView are also inherited from TextView and View. Some of the popular attributes of this widget inherited from TextView are –

S. No. XML Attributes Description
1 android:height It specifies the height of the view.
2 android:width It specifies the width of the view.
3 android:capitalize If set, it automatically capitalise all the text in the view.
4 android:cursorVisible It specifies whether cursor should be visible or invisible.
5 android:ellipsize It ellipsizes (ends with dots) text if it is too long.
6 android:gravity It specifies how text should be aligned within the view. For example, CENTER, VERTICAL_CENTER or HORITOZAL_CENTER etc.

Some of the popular attributes of Android CheckedTextView inherited from View are –

S. No. XML Attributes Description
1 android:id It specifies the unique id of the view.
2 android:clickable It specifies whether view is clickable or not.
3 android:elevation It sets base z depth of the view.
4 android:background It sets the background of the view.
5 android:alpha It sets the alpha property of the view. Values lies between 0 and 1.
6 android:padding It sets padding of the view.





At first, we will create an android application. Then, in the application we will use checkedTextView widget.

Follow the steps below to create new project. Please ignore the steps if you've already created a new project.

S. No. Steps
1 Open Android Studio.
2 Go to File => New => New Project. Write application name as CheckedTextView. Then, click next button.
3 Select minimum SDK you need. However, we have selected 14 as minimum SDK. Then, click next button.
4 Then, select Empty Activity => click next => click finish.
5 If you have followed above process correctly, you will get a newly created project successfully. However, you can also visit tutorial to Create a New Project to know steps in detail.

Now, we're going to modify xml and java file to use CheckedTextView in the project.

Open res/values/strings.xml file. Then, add below code into it.

<string name="app_name">CheckTextView</string>
<string name="checkedTextView">CheckedTextView</string>
<string name="pre_msg">CheckedTextView is</string>
<string name="checked">checked</string>
<string name="unchecked">unchecked</string>

Open res/layout/activity_main.xml file. Then, add below code into it

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

app:layout_constraintTop_toTopOf="parent" />


In activity_main.xml file, we have added a CheckedTextView. Now, we're going to access this widget in the java file.





Open src/main/java/com.ukacademe.checkedtextview/ file. Then, add below code into it.

package com.ukacademe.checktextview;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        final CheckedTextView checkedTextView = findViewById(;
        if (checkedTextView != null) {

            checkedTextView.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    checkedTextView.setCheckMarkDrawable(checkedTextView.isChecked() ? android.R.drawable.checkbox_on_background : android.R.drawable.checkbox_off_background);

                    String msg = getString(R.string.pre_msg) + " " + (checkedTextView.isChecked() ? getString(R.string.checked) : getString(R.string.unchecked));
                    Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();


We have accessed the CheckedTextView widget defined in xml file in file. Then, when CheckedTextView is clicked we set a listener to show the toast message.

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

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

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

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

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


When you run the application, you will get output as shown below.

UK Academe-CheckedTextView-Output