ClickableSpan


@RequiresCarApi(value = 2)
@CarProtocol
public final class ClickableSpan extends CarSpan


A span that makes a section of text clickable.

The text of this span will be highlighted by the host, so users understand that it is interactive. If this span overlaps the other spans (for example, ForegroundCarColorSpan), the host might choose to ignore those spans if they conflict on how clickable text is highlighted.

The host may ignore ClickableSpans unless support for it is explicitly documented in the API that takes the string.

For example, to make a portion of a text clickable:

SpannableString string = new SpannableString("Text with a clickable span");
string.setSpan(ClickableSpan.create(
    new OnClickListener
    ), 12, 22, Spanned.SPAN_INCLUSIVE_EXCLUSIVE));

Summary

Public methods

static @NonNull ClickableSpan
create(@NonNull OnClickListener onClickListener)

Creates a ClickableSpan from a OnClickListener.

boolean
@NonNull OnClickDelegate

Returns the OnClickDelegate associated with this span.

int
@NonNull String

Public methods

create

Added in 1.0.0
public static @NonNull ClickableSpan create(@NonNull OnClickListener onClickListener)

Creates a ClickableSpan from a OnClickListener.

Note that the callback relates to UI events and will be executed on the main thread using getMainLooper.

Throws
java.lang.NullPointerException

if onClickListener is null

equals

public boolean equals(@Nullable Object other)

getOnClickDelegate

Added in 1.0.0
public @NonNull OnClickDelegate getOnClickDelegate()

Returns the OnClickDelegate associated with this span.

hashCode

public int hashCode()

toString

public @NonNull String toString()