Class CheckableImageButton

All Implemented Interfaces:
Drawable.Callback, Checkable, Checkable2

public class CheckableImageButton extends ImageButton implements Checkable2
An extension to ImageButton that implements Checkable interface and is conditionally checkable, see setCheckable(boolean). The checked state is toggled on click.

This class is more lightweight than ToggleButton or RadioButton in implementing icon-only toggle buttons or radio buttons.

When used in a RadioGroup, set RadioGroup.setSelectionRequired(boolean) to true and this class can work like a RadioButton.

Since:
3.12
  • Constructor Details

  • Method Details

    • toggle

      public void toggle()
      Description copied from interface: Checkable
      Change the checked state of the view to the inverse of its current state
      Specified by:
      toggle in interface Checkable
    • performClick

      public boolean performClick()
      Description copied from class: View
      Call this view's OnClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.
      Overrides:
      performClick in class View
      Returns:
      True there was an assigned OnClickListener that was called, false otherwise is returned.
    • isChecked

      public boolean isChecked()
      Description copied from interface: Checkable
      Get the current checked state of the view
      Specified by:
      isChecked in interface Checkable
      Returns:
      The current checked state of the view
    • setChecked

      public void setChecked(boolean checked)
      Description copied from interface: Checkable
      Change the checked state of the view
      Specified by:
      setChecked in interface Checkable
      Parameters:
      checked - The new checked state
    • isCheckable

      public boolean isCheckable()
      Returns whether this image button is checkable. By default, this is true.
      See Also:
    • setCheckable

      public void setCheckable(boolean checkable)
      Sets whether this image button is checkable. By default, this is true.
      Parameters:
      checkable - Whether this button is checkable.
    • getTooltipTextOn

      @Nullable public CharSequence getTooltipTextOn()
      Returns the tooltip text for when the button is in the checked state.
      Returns:
      The tooltip text.
    • setTooltipTextOn

      public void setTooltipTextOn(@Nullable CharSequence tooltipTextOn)
      Sets the tooltip text for when the button is in the checked state. If not null, it overrides the tooltip text previously set by View.setTooltipText(java.lang.CharSequence).
      Parameters:
      tooltipTextOn - The tooltip text.
    • getTooltipTextOff

      @Nullable public CharSequence getTooltipTextOff()
      Returns the tooltip text for when the button is not in the checked state.
      Returns:
      The tooltip text.
    • setTooltipTextOff

      public void setTooltipTextOff(@Nullable CharSequence tooltipTextOff)
      Sets the tooltip text for when the button is not in the checked state. If not null, it overrides the tooltip text previously set by View.setTooltipText(java.lang.CharSequence).
      Parameters:
      tooltipTextOff - The tooltip text.
    • setOnCheckedChangeListener

      public void setOnCheckedChangeListener(@Nullable Checkable.OnCheckedChangeListener listener)
      Register a callback to be invoked when the checked state of this button changes.
      Specified by:
      setOnCheckedChangeListener in interface Checkable2
      Parameters:
      listener - the callback to call on checked state change
    • onCreateDrawableState

      @NonNull protected int[] onCreateDrawableState(int extraSpace)
      Description copied from class: View
      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 View.getDrawableState().
      Overrides:
      onCreateDrawableState in class ImageView
      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:
      an array holding the current Drawable state of the view.
      See Also: