Android APIs
public class

CheckedTextView

extends TextView
implements Checkable
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.CheckedTextView

Class Overview

An extension to TextView that supports the Checkable interface. This is useful when used in a ListView where the it's setChoiceMode has been set to something other than CHOICE_MODE_NONE.

Summary

XML Attributes
Attribute Name Related Method Description
android:checkMark setCheckMarkDrawable(int) Drawable used for the check mark graphic. 
android:checkMarkTint setCheckMarkTintList(ColorStateList) Tint to apply to the check mark. 
android:checkMarkTintMode setCheckMarkTintMode(PorterDuff.Mode) Blending mode used to apply the check mark tint. 
android:checked Indicates the initial checked state of this text. 
[Expand]
Inherited XML Attributes
From class android.widget.TextView
From class android.view.View
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
CheckedTextView(Context context)
CheckedTextView(Context context, AttributeSet attrs)
CheckedTextView(Context context, AttributeSet attrs, int defStyleAttr)
CheckedTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
Public Methods
void drawableHotspotChanged(float x, float y)
This function is called whenever the view hotspot changes and needs to be propagated to drawables managed by the view.
Drawable getCheckMarkDrawable()
Gets the checkmark drawable
ColorStateList getCheckMarkTintList()
Returns the tint applied to the check mark drawable, if specified.
PorterDuff.Mode getCheckMarkTintMode()
Returns the blending mode used to apply the tint to the check mark drawable, if specified.
boolean isChecked()
void jumpDrawablesToCurrentState()
Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.
void onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
void onRtlPropertiesChanged(int layoutDirection)
Called when any RTL property (layout direction or text direction or text alignment) has been changed.
void setCheckMarkDrawable(Drawable d)
Set the checkmark to a given Drawable.
void setCheckMarkDrawable(int resid)
Set the checkmark to a given Drawable, identified by its resourece id.
void setCheckMarkTintList(ColorStateList tint)
Applies a tint to the check mark drawable.
void setCheckMarkTintMode(PorterDuff.Mode tintMode)
Specifies the blending mode used to apply the tint specified by setCheckMarkTintList(ColorStateList) to the check mark drawable.
void setChecked(boolean checked)

Changes the checked state of this text view.

void setVisibility(int visibility)
Set the enabled state of this view.
void toggle()
Change the checked state of the view to the inverse of its current state
Protected Methods
void drawableStateChanged()
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.
int[] onCreateDrawableState(int extraSpace)
Generate the new Drawable state for this view.
void onDraw(Canvas canvas)
Implement this to do your drawing.
boolean verifyDrawable(Drawable who)
If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.
[Expand]
Inherited Methods
From class android.widget.TextView
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewTreeObserver.OnPreDrawListener
From interface android.view.accessibility.AccessibilityEventSource
From interface android.widget.Checkable

XML Attributes

android:checkMark

Drawable used for the check mark graphic.

Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

This corresponds to the global attribute resource symbol checkMark.

Related Methods

android:checkMarkTint

Tint to apply to the check mark.

Must be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol checkMarkTint.

android:checkMarkTintMode

Blending mode used to apply the check mark tint.

Must be one of the following constant values.

ConstantValueDescription
src_over3 The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]
src_in5 The tint is masked by the alpha channel of the drawable. The drawable’s color channels are thrown out. [Sa * Da, Sc * Da]
src_atop9 The tint is drawn above the drawable, but with the drawable’s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
multiply14 Multiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screen15 [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
add16 Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)

This corresponds to the global attribute resource symbol checkMarkTintMode.

android:checked

Indicates the initial checked state of this text.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol checked.

Related Methods

Public Constructors

public CheckedTextView (Context context)

Added in API level 1

public CheckedTextView (Context context, AttributeSet attrs)

Added in API level 1

public CheckedTextView (Context context, AttributeSet attrs, int defStyleAttr)

Added in API level 1

public CheckedTextView (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Added in API level 21

Public Methods

public void drawableHotspotChanged (float x, float y)

Added in API level 21

This function is called whenever the view hotspot changes and needs to be propagated to drawables managed by the view.

Be sure to call through to the superclass when overriding this function.

Parameters
x hotspot x coordinate
y hotspot y coordinate

public Drawable getCheckMarkDrawable ()

Added in API level 16

Gets the checkmark drawable

Related XML Attributes
Returns
  • The drawable use to represent the checkmark, if any.

public ColorStateList getCheckMarkTintList ()

Added in API level 21

Returns the tint applied to the check mark drawable, if specified.

Related XML Attributes
Returns
  • the tint applied to the check mark drawable

public PorterDuff.Mode getCheckMarkTintMode ()

Added in API level 21

Returns the blending mode used to apply the tint to the check mark drawable, if specified.

Related XML Attributes
Returns
  • the blending mode used to apply the tint to the check mark drawable

public boolean isChecked ()

Added in API level 1

public void jumpDrawablesToCurrentState ()

Added in API level 11

Call Drawable.jumpToCurrentState() on all Drawable objects associated with this view.

Also calls jumpToCurrentState() if there is a StateListAnimator attached to this view.

public void onInitializeAccessibilityEvent (AccessibilityEvent event)

Added in API level 14

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Added in API level 14

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info The instance to initialize.

public void onRtlPropertiesChanged (int layoutDirection)

Added in API level 17

Called when any RTL property (layout direction or text direction or text alignment) has been changed. Subclasses need to override this method to take care of cached information that depends on the resolved layout direction, or to inform child views that inherit their layout direction. The default implementation does nothing.

Parameters
layoutDirection the direction of the layout

public void setCheckMarkDrawable (Drawable d)

Added in API level 1

Set the checkmark to a given Drawable. This will be drawn when isChecked() is true.

Related XML Attributes
Parameters
d The Drawable to use for the checkmark.

public void setCheckMarkDrawable (int resid)

Added in API level 1

Set the checkmark to a given Drawable, identified by its resourece id. This will be drawn when isChecked() is true.

Related XML Attributes
Parameters
resid The Drawable to use for the checkmark.

public void setCheckMarkTintList (ColorStateList tint)

Added in API level 21

Applies a tint to the check mark drawable. Does not modify the current tint mode, which is SRC_IN by default.

Subsequent calls to setCheckMarkDrawable(Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using setTintList(ColorStateList).

Related XML Attributes
Parameters
tint the tint to apply, may be null to clear tint

public void setCheckMarkTintMode (PorterDuff.Mode tintMode)

Added in API level 21

Specifies the blending mode used to apply the tint specified by setCheckMarkTintList(ColorStateList) to the check mark drawable. The default mode is SRC_IN.

Related XML Attributes
Parameters
tintMode the blending mode used to apply the tint, may be null to clear tint

public void setChecked (boolean checked)

Added in API level 1

Changes the checked state of this text view.

Parameters
checked true to check the text, false to uncheck it

public void setVisibility (int visibility)

Added in API level 1

Set the enabled state of this view.

Parameters
visibility One of VISIBLE, INVISIBLE, or GONE.

public void toggle ()

Added in API level 1

Change the checked state of the view to the inverse of its current state

Protected Methods

protected void drawableStateChanged ()

Added in API level 1

This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.

If the View has a StateListAnimator, it will also be called to run necessary state change animations.

Be sure to call through to the superclass when overriding this function.

protected int[] onCreateDrawableState (int extraSpace)

Added in API level 1

Generate the new Drawable state for this view. This is called by the view system when the cached Drawable state is determined to be invalid. To retrieve the current state, you should use getDrawableState().

Parameters
extraSpace if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.
Returns
  • Returns an array holding the current Drawable state of the view.

protected void onDraw (Canvas canvas)

Added in API level 1

Implement this to do your drawing.

Parameters
canvas the canvas on which the background will be drawn

protected boolean verifyDrawable (Drawable who)

Added in API level 1

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.

Parameters
who The Drawable to verify. Return true if it is one you are displaying, else return the result of calling through to the super class.
Returns
  • boolean If true than the Drawable is being displayed in the view; else false and it is not allowed to animate.