Spannable

  • Spannable is an interface for attaching and detaching markup objects to text, extending the Spanned interface.

  • It's implemented by classes like Editable, SpannableString, and SpannableStringBuilder, offering varying levels of mutability.

  • Key methods include setSpan() to attach markup and removeSpan() to detach it, influencing text display and behavior.

  • It inherits constants from Spanned that define span behavior, like SPAN_EXCLUSIVE_EXCLUSIVE and SPAN_INCLUSIVE_INCLUSIVE.

  • Developers can utilize Spannable to implement rich text functionalities within their applications.

public interface Spannable implements Spanned
Known Indirect Subclasses

This is the interface for text to which markup objects can be attached and detached. Not all Spannable classes have mutable text; see Editable for that.

Nested Class Summary

class Spannable.Factory Factory used by TextView to create new Spannables. 

Inherited Constant Summary

Public Method Summary

abstract void
removeSpan(Object what)
Remove the specified object from the range of text to which it was attached, if any.
abstract void
setSpan(Object what, int start, int end, int flags)
Attach the specified markup object to the range start…end of the text, or move the object to that range if it was already attached elsewhere.

Inherited Method Summary

Public Methods

public abstract void removeSpan (Object what)

Remove the specified object from the range of text to which it was attached, if any. It is OK to remove an object that was never attached in the first place.

Parameters
what

public abstract void setSpan (Object what, int start, int end, int flags)

Attach the specified markup object to the range start…end of the text, or move the object to that range if it was already attached elsewhere. See Spanned for an explanation of what the flags mean. The object can be one that has meaning only within your application, or it can be one that the text system will use to affect text display or behavior. Some noteworthy ones are TextWatcher and SpanWatcher.

Parameters
what
start
end
flags