# URLSpan

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# URLSpan

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/text/style/URLSpan "View this page in Java")  

```
open class URLSpan : ClickableSpan, ParcelableSpan
```

|---|---|---|----------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                 ||||
| ↳ | [android.text.style.CharacterStyle](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle) |||
|   | ↳ | [android.text.style.ClickableSpan](https://developer.android.com/reference/kotlin/android/text/style/ClickableSpan) ||
|   |   | ↳ | [android.text.style.URLSpan](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#) |

Implementation of the[ClickableSpan](https://developer.android.com/reference/kotlin/android/text/style/ClickableSpan)that allows setting a url string. When selecting and clicking on the text to which the span is attached, the`URLSpan`will try to open the url, by launching an an Activity with an[Intent.ACTION_VIEW](https://developer.android.com/reference/kotlin/android/content/Intent.html#ACTION_VIEW:kotlin.String)intent.

For example, a`URLSpan`can be used like this:  

```kotlin
SpannableString string = new SpannableString("Text with a url span");
  string.setSpan(new URLSpan("http://www.developer.android.com"), 12, 15, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
  
```
Text with`URLSpan`.

## Summary

|                                                                                                                                                       Public constructors                                                                                                                                                        ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [URLSpan](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#URLSpan(android.os.Parcel))`(`src:` `[Parcel](https://developer.android.com/reference/kotlin/android/os/Parcel.html#)`)` Constructs a[URLSpan](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#)from a parcel.  |
| [URLSpan](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#URLSpan(kotlin.String))`(`url:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Constructs a[URLSpan](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#)from a url string. |

|                                                                                                                                                                                                                      Public methods                                                                                                                                                                                                                       ||
|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)        | [describeContents](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#describeContents())`()` <br />                                                                                                                                                                                                                                        |
| open[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)        | [getSpanTypeId](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#getSpanTypeId())`()` <br />                                                                                                                                                                                                                                              |
| open[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | [getURL](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#getURL())`()` Get the url string for this span.                                                                                                                                                                                                                                 |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)      | [onClick](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#onClick(android.view.View))`(`widget:` `[View](https://developer.android.com/reference/kotlin/android/view/View.html#)`)` <br />                                                                                                                                               |
| open[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)  | [toString](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#toString())`()` <br />                                                                                                                                                                                                                                                        |
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)      | [writeToParcel](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#writeToParcel(android.os.Parcel,%20kotlin.Int))`(`dest:` `[Parcel](https://developer.android.com/reference/kotlin/android/os/Parcel.html#)`, `flags:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Flatten this object in to a Parcel. |

| Inherited functions ||
|---|---|
| From class[CharacterStyle](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle) |-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [CharacterStyle](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle)! | [getUnderlying](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle#getUnderlying())`()` <br /> Returns "this" for most CharacterStyles, but for CharacterStyles that were generated by[wrap](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle#wrap(android.text.style.CharacterStyle)), returns the underlying CharacterStyle. <br />                                                                                                                                                                            | | [CharacterStyle](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle)! | [wrap](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle#wrap(android.text.style.CharacterStyle))`(`cs:` `[CharacterStyle](https://developer.android.com/reference/kotlin/android/text/style/CharacterStyle)!`)` <br /> 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. <br /> | ||
| From class[ClickableSpan](https://developer.android.com/reference/kotlin/android/text/style/ClickableSpan) |------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [updateDrawState](https://developer.android.com/reference/kotlin/android/text/style/ClickableSpan#updateDrawState(android.text.TextPaint))`(`ds:` `[TextPaint](https://developer.android.com/reference/kotlin/android/text/TextPaint.html#)`)` <br /> Makes the text underlined and in the link color. <br /> | ||

## Public constructors

### URLSpan

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
URLSpan(src: Parcel)
```

Constructs a[URLSpan](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#)from a parcel.

|                                                     Parameters                                                      ||
|-------|--------------------------------------------------------------------------------------------------------------|
| `src` | [Parcel](https://developer.android.com/reference/kotlin/android/os/Parcel.html#):This value cannot be`null`. |

### URLSpan

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
URLSpan(url: String!)
```

Constructs a[URLSpan](https://developer.android.com/reference/kotlin/android/text/style/URLSpan#)from a url string.

|                                               Parameters                                                ||
|-------|--------------------------------------------------------------------------------------------------|
| `url` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!:the url string |

## Public methods

### describeContents

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun describeContents(): Int
```

|                                                                                                                                                                               Return                                                                                                                                                                               ||
|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either`0`or[android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#CONTENTS_FILE_DESCRIPTOR:kotlin.Int) |

### getSpanTypeId

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun getSpanTypeId(): Int
```  

### getURL

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun getURL(): String!
```

Get the url string for this span.

|                                               Return                                               ||
|-----------------------------------------------------------------------------------|-----------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)! | the url string. |

### onClick

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun onClick(widget: View): Unit
```

|                                                      Parameters                                                      ||
|----------|------------------------------------------------------------------------------------------------------------|
| `widget` | [View](https://developer.android.com/reference/kotlin/android/view/View.html#):This value cannot be`null`. |

### toString

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun toString(): String
```

|                                                          Return                                                          ||
|----------------------------------------------------------------------------------|----------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | a string representation of the object. |

### writeToParcel

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun writeToParcel(
    dest: Parcel, 
    flags: Int
): Unit
```

Flatten this object in to a Parcel.

|                                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                                     ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dest`  | [Parcel](https://developer.android.com/reference/kotlin/android/os/Parcel.html#):This value cannot be`null`.                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `flags` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Additional flags about how the object should be written. May be 0 or[PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int). Value is either`0`or a combination of[android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int), and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |