Class BackgroundColorSpan

java.lang.Object
icyllis.modernui.text.style.CharacterStyle
icyllis.modernui.text.style.BackgroundColorSpan
All Implemented Interfaces:
ParcelableSpan, UpdateAppearance, Parcelable

public class BackgroundColorSpan extends CharacterStyle implements UpdateAppearance, ParcelableSpan
Changes the background color of the text to which the span is attached.

For example, to set a green background color for a text you would create a SpannableString based on the text and set the span.


 SpannableString string = new SpannableString("Text with a background color span");
 string.setSpan(new BackgroundColorSpan(color), 12, 28, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  • Constructor Details

    • BackgroundColorSpan

      public BackgroundColorSpan(@ColorInt int color)
      Creates a BackgroundColorSpan from a color integer.
      Parameters:
      color - color integer that defines the background color
    • BackgroundColorSpan

      public BackgroundColorSpan(@NonNull Parcel src)
      Creates a BackgroundColorSpan from a parcel.
  • Method Details

    • getSpanTypeId

      public int getSpanTypeId()
      Description copied from interface: ParcelableSpan
      Return a special type identifier for this span class.
      Specified by:
      getSpanTypeId in interface ParcelableSpan
    • writeToParcel

      public void writeToParcel(@NonNull Parcel dest, int flags)
      Description copied from interface: Parcelable
      The subclass implements the method to flatten its contents by calling the methods of Parcel for its primitive values.
      Specified by:
      writeToParcel in interface Parcelable
      Parameters:
      dest - the parcel to write the object's data to
      flags - the flags about how the object should be written
    • getBackgroundColor

      @ColorInt public int getBackgroundColor()
      Returns:
      the background color of this span.
      See Also:
    • updateDrawState

      public void updateDrawState(@NonNull TextPaint paint)
      Updates the background color of the TextPaint.
      Specified by:
      updateDrawState in class CharacterStyle