Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change checkMark or size of CheckedTextView

I'm working on an application where I'm using a checkedTextView, it all works great. But I really don't like that layout of the "checkbox" within the checkedTextView, it's simply to big. Is there any way to resize it or change the layout to something custom made?

I've tried the android:checkMark attribute, but that resulted in it being marked all the time, and thus showing all the time.

like image 420
Nicholas Magnussen Avatar asked Oct 31 '11 13:10

Nicholas Magnussen


People also ask

How to use CheckedTextView in android Studio?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken CheckedTextView, when user clicked on textview, it will show check image.

What is CheckedTextView?

android.widget.CheckedTextView. An extension to TextView that supports the Checkable interface and displays. This is useful when used in a ListView where the setChoiceMode has been set to something other than CHOICE_MODE_NONE .

What is Checked text view in android Studio?

In Android, CheckedTextView is an extension of normal 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.


1 Answers

Instead of using a single drawable you should write a selector:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/drawable_checked"
        android:state_checked="true" />
    <item
        android:drawable="@drawable/drawable_unchecked"
        android:state_checked="false" />
</selector>

And then set it to the android:checkMark attribute.

like image 160
rciovati Avatar answered Sep 22 '22 10:09

rciovati