ClickableSpan
@RequiresCarApi(value = 2)
@CarProtocol
public final class ClickableSpan extends CarSpan
| java.lang.Object | |||
| ↳ | android.text.style.CharacterStyle | ||
| ↳ | androidx.car.app.model.CarSpan | ||
| ↳ | androidx.car.app.model.ClickableSpan |
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 |
boolean |
|
@NonNull OnClickDelegate |
Returns the |
int |
hashCode() |
@NonNull String |
toString() |
Inherited methods |
||||||
|---|---|---|---|---|---|---|
|
||||||
|
Public methods
create
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 |
getOnClickDelegate
public @NonNull OnClickDelegate getOnClickDelegate()
Returns the OnClickDelegate associated with this span.