CheckedTextView

public class CheckedTextView
extends TextView implements Checkable

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ 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.

Summary

XML attributes

android:checkMark Drawable used for the check mark graphic. 
android:checkMarkTint Tint to apply to the check mark. 
android:checkMarkTintMode Blending mode used to apply the check mark tint. 
android:checked Indicates the initial checked state of this text. 

Inherited XML attributes

Inherited constants

Inherited fields

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 or child views managed by the view.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

Drawable getCheckMarkDrawable()

Gets the checkmark drawable

BlendMode getCheckMarkTintBlendMode()

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

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 onRestoreInstanceState(Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

void onRtlPropertiesChanged(int layoutDirection)

Called when any RTL property (layout direction or text direction or text alignment) has been changed.

Parcelable onSaveInstanceState()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

void setCheckMarkDrawable(Drawable d)

Set the check mark to the specified drawable.

void setCheckMarkDrawable(int resId)

Sets the check mark to the drawable with the specified resource ID.

void setCheckMarkTintBlendMode(BlendMode tintMode)

Specifies the blending mode used to apply the tint specified by setCheckMarkTintList(android.content.res.ColorStateList) to the check mark drawable.

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(android.content.res.ColorStateList) to the check mark drawable.

void setChecked(boolean checked)

Sets the checked state of this view.

void setVisibility(int visibility)

Set the visibility 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.

Inherited methods

XML attributes

android:checkMark

Drawable used for the check mark graphic.

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

Related methods:

android:checkMarkTint

Tint to apply to the check mark.

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

Related methods:

android:checkMarkTintMode

Blending mode used to apply the check mark tint.

Must be one of the following constant values.

ConstantValueDescription
add10Combines the tint and drawable color and alpha channels, clamping the result to valid color values. Saturate(S + D)
multiplyeMultiplies the color and alpha channels of the drawable with those of the tint. [Sa * Da, Sc * Dc]
screenf[Sa + Da - Sa * Da, Sc + Dc - Sc * Dc]
src_atop9The tint is drawn above the drawable, but with the drawable\u2019s alpha channel masking the result. [Da, Sc * Da + (1 - Sa) * Dc]
src_in5The tint is masked by the alpha channel of the drawable. The drawable\u2019s color channels are thrown out. [Sa * Da, Sc * Da]
src_over3The tint is drawn on top of the drawable. [Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc]

Related methods:

android:checked

Indicates the initial checked state of this text.

May be a boolean value, such as "true" or "false".

Public constructors

CheckedTextView

Added in API level 1
public CheckedTextView (Context context)

Parameters
context Context

CheckedTextView

Added in API level 1
public CheckedTextView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

CheckedTextView

Added in API level 1
public CheckedTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

CheckedTextView

Added in API level 1
public CheckedTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

drawableHotspotChanged

Added in API level 21
public void drawableHotspotChanged (float x, 
                float y)

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

Dispatching to child views is handled by dispatchDrawableHotspotChanged(float, float).

Be sure to call through to the superclass when overriding this function.
If you override this method you must call through to the superclass implementation.

Parameters
x float: hotspot x coordinate

y float: hotspot y coordinate

getAccessibilityClassName

Added in API level 23
public CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getCheckMarkDrawable

Added in API level 16
public Drawable getCheckMarkDrawable ()

Gets the checkmark drawable

Related XML Attributes:

Returns
Drawable The drawable use to represent the checkmark, if any.

getCheckMarkTintBlendMode

Added in API level 29
public BlendMode getCheckMarkTintBlendMode ()

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

Related XML Attributes:

Returns
BlendMode the blending mode used to apply the tint to the check mark drawable This value may be null.

getCheckMarkTintList

Added in API level 21
public ColorStateList getCheckMarkTintList ()

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

Related XML Attributes:

Returns
ColorStateList the tint applied to the check mark drawable This value may be null.

getCheckMarkTintMode

Added in API level 21
public PorterDuff.Mode getCheckMarkTintMode ()

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

Related XML Attributes:

Returns
PorterDuff.Mode the blending mode used to apply the tint to the check mark drawable This value may be null.

isChecked

Added in API level 1
public boolean isChecked ()

Returns
boolean

jumpDrawablesToCurrentState

Added in API level 11
public void jumpDrawablesToCurrentState ()

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

Also calls StateListAnimator#jumpToCurrentState() if there is a StateListAnimator attached to this view.
If you override this method you must call through to the superclass implementation.

onRestoreInstanceState

Added in API level 1
public void onRestoreInstanceState (Parcelable state)

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.
If you override this method you must call through to the superclass implementation.

Parameters
state Parcelable: The frozen state that had previously been returned by onSaveInstanceState().

onRtlPropertiesChanged

Added in API level 17
public void onRtlPropertiesChanged (int layoutDirection)

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 int: the direction of the layout Value is View.LAYOUT_DIRECTION_LTR, or View.LAYOUT_DIRECTION_RTL

onSaveInstanceState

Added in API level 1
public Parcelable onSaveInstanceState ()

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can not be reconstructed later. For example, you will never store your current position on screen because that will be computed again when a new instance of the view is placed in its view hierarchy.

Some examples of things you may store here: the current cursor position in a text view (but usually not the text itself since that is stored in a content provider or other persistent storage), the currently selected item in a list view.
If you override this method you must call through to the superclass implementation.

Returns
Parcelable Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.

setCheckMarkDrawable

Added in API level 1
public void setCheckMarkDrawable (Drawable d)

Set the check mark to the specified drawable.

When this view is checked, the drawable's state set will include R.attr.state_checked.

Related XML Attributes:

Parameters
d Drawable: the drawable to use for the check mark This value may be null.

setCheckMarkDrawable

Added in API level 1
public void setCheckMarkDrawable (int resId)

Sets the check mark to the drawable with the specified resource ID.

When this view is checked, the drawable's state set will include R.attr.state_checked.

Related XML Attributes:

Parameters
resId int: the resource identifier of drawable to use as the check mark

setCheckMarkTintBlendMode

Added in API level 29
public void setCheckMarkTintBlendMode (BlendMode tintMode)

Specifies the blending mode used to apply the tint specified by setCheckMarkTintList(android.content.res.ColorStateList) to the check mark drawable. The default mode is PorterDuff.Mode#SRC_IN.

Related XML Attributes:

Parameters
tintMode BlendMode: the blending mode used to apply the tint, may be null to clear tint

setCheckMarkTintList

Added in API level 21
public void setCheckMarkTintList (ColorStateList tint)

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

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

Related XML Attributes:

Parameters
tint ColorStateList: the tint to apply, may be null to clear tint

setCheckMarkTintMode

Added in API level 21
public void setCheckMarkTintMode (PorterDuff.Mode tintMode)

Specifies the blending mode used to apply the tint specified by setCheckMarkTintList(android.content.res.ColorStateList) to the check mark drawable. The default mode is PorterDuff.Mode#SRC_IN.

Related XML Attributes:

Parameters
tintMode PorterDuff.Mode: the blending mode used to apply the tint, may be null to clear tint

setChecked

Added in API level 1
public void setChecked (boolean checked)

Sets the checked state of this view.

Parameters
checked boolean: true set the state to checked, false to uncheck

setVisibility

Added in API level 1
public void setVisibility (int visibility)

Set the visibility state of this view.

Parameters
visibility int: One of View.VISIBLE, View.INVISIBLE, or View.GONE. Value is View.VISIBLE, View.INVISIBLE, or View.GONE

toggle

Added in API level 1
public void toggle ()

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

Protected methods

drawableStateChanged

Added in API level 1
protected 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.

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.
If you override this method you must call through to the superclass implementation.

onCreateDrawableState

Added in API level 1
protected int[] onCreateDrawableState (int extraSpace)

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 int: 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
int[] Returns an array holding the current Drawable state of the view.

onDraw

Added in API level 1
protected void onDraw (Canvas canvas)

Implement this to do your drawing.

Parameters
canvas Canvas: the canvas on which the background will be drawn This value cannot be null.

verifyDrawable

Added in API level 1
protected 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. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.
If you override this method you must call through to the superclass implementation.

Parameters
who Drawable: This value cannot be null.

Returns
boolean boolean If true then the Drawable is being displayed in the view; else false and it is not allowed to animate.