Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/text/style/ReplacementSpan#pubctors) \| [Methods](https://developer.android.com/reference/android/text/style/ReplacementSpan#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/text/style/ReplacementSpan#inhmethods)

# ReplacementSpan

*** ** * ** ***

` public abstract class ReplacementSpan `   
` ` ` ` ` extends https://developer.android.com/reference/android/text/style/MetricAffectingSpan ` ` `

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||||
| ↳ | [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle) |||
|   | ↳ | [android.text.style.MetricAffectingSpan](https://developer.android.com/reference/android/text/style/MetricAffectingSpan) ||
|   |   | ↳ | android.text.style.ReplacementSpan |

Known direct subclasses [DynamicDrawableSpan](https://developer.android.com/reference/android/text/style/DynamicDrawableSpan) [DynamicDrawableSpan](https://developer.android.com/reference/android/text/style/DynamicDrawableSpan) Span that replaces the text it's attached to with a `https://developer.android.com/reference/android/graphics/drawable/Drawable` that can be aligned with the bottom or with the baseline of the surrounding text. Known indirect subclasses [ImageSpan](https://developer.android.com/reference/android/text/style/ImageSpan) [ImageSpan](https://developer.android.com/reference/android/text/style/ImageSpan) Span that replaces the text it's attached to with a `https://developer.android.com/reference/android/graphics/drawable/Drawable` that can be aligned with the bottom or with the baseline of the surrounding text.   

*** ** * ** ***

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/text/style/ReplacementSpan#ReplacementSpan()() ` |

| ### Public methods ||
|---|---|
| ` abstract void` | ` https://developer.android.com/reference/android/text/style/ReplacementSpan#draw(android.graphics.Canvas,%20java.lang.CharSequence,%20int,%20int,%20float,%20int,%20int,%20int,%20android.graphics.Paint)(https://developer.android.com/reference/android/graphics/Canvas canvas, https://developer.android.com/reference/java/lang/CharSequence text, int start, int end, float x, int top, int y, int bottom, https://developer.android.com/reference/android/graphics/Paint paint) ` Draws the span into the canvas. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/text/style/ReplacementSpan#getContentDescription()() ` Gets a brief description of this ReplacementSpan for use in accessibility support. |
| ` abstract int` | ` https://developer.android.com/reference/android/text/style/ReplacementSpan#getSize(android.graphics.Paint,%20java.lang.CharSequence,%20int,%20int,%20android.graphics.Paint.FontMetricsInt)(https://developer.android.com/reference/android/graphics/Paint paint, https://developer.android.com/reference/java/lang/CharSequence text, int start, int end, https://developer.android.com/reference/android/graphics/Paint.FontMetricsInt fm) ` Returns the width of the span. |
| ` void` | ` https://developer.android.com/reference/android/text/style/ReplacementSpan#setContentDescription(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence contentDescription) ` Sets the specific content description into ReplacementSpan. |
| ` void` | ` https://developer.android.com/reference/android/text/style/ReplacementSpan#updateDrawState(android.text.TextPaint)(https://developer.android.com/reference/android/text/TextPaint ds) ` This method does nothing, since ReplacementSpans are drawn explicitly instead of affecting Paint properties. |
| ` void` | ` https://developer.android.com/reference/android/text/style/ReplacementSpan#updateMeasureState(android.text.TextPaint)(https://developer.android.com/reference/android/text/TextPaint p) ` This method does nothing, since ReplacementSpans are measured explicitly instead of affecting Paint properties. |

### Inherited methods

From class ` https://developer.android.com/reference/android/text/style/MetricAffectingSpan ` ` https://developer.android.com/reference/android/text/style/MetricAffectingSpan` ` https://developer.android.com/reference/android/text/style/MetricAffectingSpan#getUnderlying()() `

Returns "this" for most MetricAffectingSpans, but for MetricAffectingSpans that were generated by `https://developer.android.com/reference/android/text/style/CharacterStyle#wrap(android.text.style.CharacterStyle)`, returns the underlying MetricAffectingSpan.
` abstract void` ` https://developer.android.com/reference/android/text/style/MetricAffectingSpan#updateMeasureState(android.text.TextPaint)(https://developer.android.com/reference/android/text/TextPaint textPaint) `

Classes that extend MetricAffectingSpan implement this method to update the text formatting in a way that can change the width or height of characters.
From class ` https://developer.android.com/reference/android/text/style/CharacterStyle ` ` https://developer.android.com/reference/android/text/style/CharacterStyle` ` https://developer.android.com/reference/android/text/style/CharacterStyle#getUnderlying()() `

Returns "this" for most CharacterStyles, but for CharacterStyles that were generated by `https://developer.android.com/reference/android/text/style/CharacterStyle#wrap(android.text.style.CharacterStyle)`, returns the underlying CharacterStyle.
` abstract void` ` https://developer.android.com/reference/android/text/style/CharacterStyle#updateDrawState(android.text.TextPaint)(https://developer.android.com/reference/android/text/TextPaint tp) ` ` static https://developer.android.com/reference/android/text/style/CharacterStyle` ` https://developer.android.com/reference/android/text/style/CharacterStyle#wrap(android.text.style.CharacterStyle)(https://developer.android.com/reference/android/text/style/CharacterStyle cs) `

A given CharacterStyle can only applied to a single region of a given Spanned.
From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public constructors

### ReplacementSpan

```
public ReplacementSpan ()
```

<br />

<br />

## Public methods

### draw

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

```
public abstract void draw (Canvas canvas, 
                CharSequence text, 
                int start, 
                int end, 
                float x, 
                int top, 
                int y, 
                int bottom, 
                Paint paint)
```

Draws the span into the canvas.

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas`: Canvas into which the span should be rendered. This value cannot be `null`. <br /> |
| `text` | `CharSequence`: Current text. <br /> |
| `start` | `int`: Start character index for span. Value is 0 or greater <br /> |
| `end` | `int`: End character index for span. Value is 0 or greater <br /> |
| `x` | `float`: Edge of the replacement closest to the leading margin. <br /> |
| `top` | `int`: Top of the line. <br /> |
| `y` | `int`: Baseline. <br /> |
| `bottom` | `int`: Bottom of the line. <br /> |
| `paint` | `Paint`: Paint instance. This value cannot be `null`. <br /> |

### getContentDescription

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

```
public CharSequence getContentDescription ()
```

Gets a brief description of this ReplacementSpan for use in accessibility support.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | The content description. This value may be `null`. <br /> |

### getSize

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

```
public abstract int getSize (Paint paint, 
                CharSequence text, 
                int start, 
                int end, 
                Paint.FontMetricsInt fm)
```

Returns the width of the span. Extending classes can set the height of the span by updating attributes of `https://developer.android.com/reference/android/graphics/Paint.FontMetricsInt`. If the span covers the whole text, and the height is not set, `https://developer.android.com/reference/android/text/style/ReplacementSpan#draw(android.graphics.Canvas,%20java.lang.CharSequence,%20int,%20int,%20float,%20int,%20int,%20int,%20android.graphics.Paint)` will not be called for the span.

<br />

| Parameters ||
|---|---|
| `paint` | `Paint`: Paint instance. This value cannot be `null`. <br /> |
| `text` | `CharSequence`: Current text. <br /> |
| `start` | `int`: Start character index for span. Value is 0 or greater <br /> |
| `end` | `int`: End character index for span. Value is 0 or greater <br /> |
| `fm` | `Paint.FontMetricsInt`: Font metrics, can be null. <br /> |

| Returns ||
|---|---|
| `int` | Width of the span. <br /> |

### setContentDescription

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

```
public void setContentDescription (CharSequence contentDescription)
```

Sets the specific content description into ReplacementSpan. ReplacementSpans are shared with accessibility services, but only the content description is available from them.

<br />

| Parameters ||
|---|---|
| `contentDescription` | `CharSequence`: content description. The default value is null. <br /> |

### updateDrawState

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

```
public void updateDrawState (TextPaint ds)
```

This method does nothing, since ReplacementSpans are drawn explicitly instead of affecting Paint properties.

<br />

| Parameters ||
|---|---|
| `ds` | `TextPaint` <br /> |

### updateMeasureState

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

```
public void updateMeasureState (TextPaint p)
```

This method does nothing, since ReplacementSpans are measured explicitly instead of affecting Paint properties.

<br />

| Parameters ||
|---|---|
| `p` | `TextPaint`: the paint used for drawing the text. This value cannot be `null`. <br /> |