Stay organized with collections
Save and categorize content based on your preferences.
ClickableSpan
abstract class ClickableSpan : CharacterStyle, UpdateAppearance
If an object of this type is attached to the text of a TextView with a movement method of LinkMovementMethod, the affected spans of text can be selected. If selected and clicked, the onClick
method will be called.
The text with a ClickableSpan
attached will be underlined and the link color will be used as a text color. The default link color is the theme's accent color or android:textColorLink
if this attribute is defined in the theme. For example, considering that we have a CustomClickableSpan
that extends ClickableSpan
, it can be used like this:
<code>SpannableString string = new SpannableString("Text with clickable text");
string.setSpan(new CustomClickableSpan(), 10, 19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</code>
Text with
ClickableSpan
.
Summary
Public methods |
abstract Unit |
Performs the click action associated with this span.
|
open String |
|
open Unit |
Makes the text underlined and in the link color.
|
Inherited functions |
From class CharacterStyle
CharacterStyle! |
getUnderlying()
Returns "this" for most CharacterStyles, but for CharacterStyles that were generated by wrap , returns the underlying CharacterStyle.
|
CharacterStyle! |
wrap(cs: CharacterStyle!)
A given CharacterStyle can only applied to a single region of a given Spanned. If you need to attach the same CharacterStyle to multiple regions, you can use this method to wrap it with a new object that will have the same effect but be a distinct object so that it can also be attached without conflict.
|
|
Public constructors
ClickableSpan
ClickableSpan()
Public methods
onClick
abstract fun onClick(widget: View): Unit
Performs the click action associated with this span.
Parameters |
widget |
View: This value cannot be null . |
toString
open fun toString(): String
Return |
String |
a string representation of the object. |
updateDrawState
open fun updateDrawState(ds: TextPaint): Unit
Makes the text underlined and in the link color.
Parameters |
ds |
TextPaint: This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ClickableSpan\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nClickableSpan\n=============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/text/style/ClickableSpan \"View this page in Java\") \n\n```\nabstract class ClickableSpan : CharacterStyle, UpdateAppearance\n```\n\n|---|---|---------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||\n| ↳ | [android.text.style.CharacterStyle](/reference/kotlin/android/text/style/CharacterStyle) ||\n| | ↳ | [android.text.style.ClickableSpan](#) |\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known Direct Subclasses [TextLinks.TextLinkSpan](../../view/textclassifier/TextLinks.TextLinkSpan.html#), [URLSpan](/reference/kotlin/android/text/style/URLSpan) |----------------------------------------------------------------------------------|----------------------------------------------------------------------------| | [TextLinks.TextLinkSpan](../../view/textclassifier/TextLinks.TextLinkSpan.html#) | A ClickableSpan for a TextLink. | | [URLSpan](/reference/kotlin/android/text/style/URLSpan) | Implementation of the [ClickableSpan](#) that allows setting a url string. | |\n\nIf an object of this type is attached to the text of a TextView with a movement method of LinkMovementMethod, the affected spans of text can be selected. If selected and clicked, the [onClick](#onClick(android.view.View)) method will be called.\n\nThe text with a `ClickableSpan` attached will be underlined and the link color will be used as a text color. The default link color is the theme's accent color or `android:textColorLink` if this attribute is defined in the theme. For example, considering that we have a `CustomClickableSpan` that extends `ClickableSpan`, it can be used like this: \n\n```kotlin\n\u003ccode\u003eSpannableString string = new SpannableString(\"Text with clickable text\");\n string.setSpan(new CustomClickableSpan(), 10, 19, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);\u003c/code\u003e\n```\nText with `ClickableSpan`.\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------------------|---|\n| [ClickableSpan](#ClickableSpan())`()` \u003cbr /\u003e |\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onClick](#onClick(android.view.View))`(`widget:` `[View](../../view/View.html#)`)` Performs the click action associated with this span. |\n| open [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | [toString](#toString())`()` \u003cbr /\u003e |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [updateDrawState](#updateDrawState(android.text.TextPaint))`(`ds:` `[TextPaint](../TextPaint.html#)`)` Makes the text underlined and in the link color. |\n\n| Inherited functions ||\n|---|---|\n| From class [CharacterStyle](/reference/kotlin/android/text/style/CharacterStyle) |------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [CharacterStyle](/reference/kotlin/android/text/style/CharacterStyle)! | [getUnderlying](/reference/kotlin/android/text/style/CharacterStyle#getUnderlying())`()` Returns \"this\" for most CharacterStyles, but for CharacterStyles that were generated by [wrap](/reference/kotlin/android/text/style/CharacterStyle#wrap(android.text.style.CharacterStyle)), returns the underlying CharacterStyle. \u003cbr /\u003e | | [CharacterStyle](/reference/kotlin/android/text/style/CharacterStyle)! | [wrap](/reference/kotlin/android/text/style/CharacterStyle#wrap(android.text.style.CharacterStyle))`(`cs:` `[CharacterStyle](/reference/kotlin/android/text/style/CharacterStyle)!`)` A given CharacterStyle can only applied to a single region of a given Spanned. If you need to attach the same CharacterStyle to multiple regions, you can use this method to wrap it with a new object that will have the same effect but be a distinct object so that it can also be attached without conflict. \u003cbr /\u003e | ||\n\nPublic constructors\n-------------------\n\n### ClickableSpan\n\n```\nClickableSpan()\n```\n\nPublic methods\n--------------\n\n### onClick\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onClick(widget: View): Unit\n```\n\nPerforms the click action associated with this span.\n\n| Parameters ||\n|----------|-------------------------------------------------------------|\n| `widget` | [View](../../view/View.html#): This value cannot be `null`. |\n\n### toString\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun toString(): String\n```\n\n| Return ||\n|----------------------------------------------------------------------------------|----------------------------------------|\n| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | a string representation of the object. |\n\n### updateDrawState\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun updateDrawState(ds: TextPaint): Unit\n```\n\nMakes the text underlined and in the link color.\n\n| Parameters ||\n|------|---------------------------------------------------------------|\n| `ds` | [TextPaint](../TextPaint.html#): This value cannot be `null`. |"]]