# IconMarginSpan

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/IconMarginSpan#pubctors)\|[Methods](https://developer.android.com/reference/android/text/style/IconMarginSpan#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/text/style/IconMarginSpan#inhmethods)  

# IconMarginSpan

*** ** * ** ***

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

`
public


class
IconMarginSpan
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


implements

`[LeadingMarginSpan](https://developer.android.com/reference/android/text/style/LeadingMarginSpan)`,

`[LineHeightSpan](https://developer.android.com/reference/android/text/style/LineHeightSpan)`


`

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

<br />

*** ** * ** ***

Paragraph affecting span, that draws a bitmap at the beginning of a text. The span also allows setting a padding between the bitmap and the text. The default value of the padding is 0px. The span should be attached from the first character of the text.

For example, an`IconMarginSpan`with a bitmap and a padding of 30px can be set like this:  

```
 SpannableString string = new SpannableString("Text with icon and padding");
 string.setSpan(new IconMarginSpan(bitmap, 30), 0, string.length(),
 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
 
```
![](https://developer.android.com/static/reference/android/images/text/style/iconmarginspan.png)Text with`IconMarginSpan`

<br />

**See also:**

- [for working with a {@link android.graphics.drawable.Drawable} instead of
  a {@link android.graphics.Bitmap Bitmap}.](https://developer.android.com/reference/android/text/style/DrawableMarginSpan)

## Summary

|                                                                                                                                                                                                        ### Public constructors                                                                                                                                                                                                         ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[IconMarginSpan](https://developer.android.com/reference/android/text/style/IconMarginSpan#IconMarginSpan(android.graphics.Bitmap))`(`[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap)` bitmap) ` Creates an[IconMarginSpan](https://developer.android.com/reference/android/text/style/IconMarginSpan)from a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap).                 |
| ` `[IconMarginSpan](https://developer.android.com/reference/android/text/style/IconMarginSpan#IconMarginSpan(android.graphics.Bitmap,%20int))`(`[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap)` bitmap, int pad) ` Creates an[IconMarginSpan](https://developer.android.com/reference/android/text/style/IconMarginSpan)from a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap). |

|                                                                                                                                                                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                     ||
|------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                      | ` `[chooseHeight](https://developer.android.com/reference/android/text/style/IconMarginSpan#chooseHeight(java.lang.CharSequence,%20int,%20int,%20int,%20int,%20android.graphics.Paint.FontMetricsInt))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, int start, int end, int istartv, int v, `[Paint.FontMetricsInt](https://developer.android.com/reference/android/graphics/Paint.FontMetricsInt)` fm) ` Classes that implement this should define how the height is being calculated.                                                                                                                                                                                                          |
| ` void`                                                                      | ` `[drawLeadingMargin](https://developer.android.com/reference/android/text/style/IconMarginSpan#drawLeadingMargin(android.graphics.Canvas,%20android.graphics.Paint,%20int,%20int,%20int,%20int,%20int,%20java.lang.CharSequence,%20int,%20int,%20boolean,%20android.text.Layout))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas)` c, `[Paint](https://developer.android.com/reference/android/graphics/Paint)` p, int x, int dir, int top, int baseline, int bottom, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, int start, int end, boolean first, `[Layout](https://developer.android.com/reference/android/text/Layout)` layout) ` Renders the leading margin. |
| ` `[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap) | ` `[getBitmap](https://developer.android.com/reference/android/text/style/IconMarginSpan#getBitmap())`() ` Returns the bitmap to be used at the beginning of the text                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` int`                                                                       | ` `[getLeadingMargin](https://developer.android.com/reference/android/text/style/IconMarginSpan#getLeadingMargin(boolean))`(boolean first) ` Returns the amount by which to adjust the leading margin.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` int`                                                                       | ` `[getPadding](https://developer.android.com/reference/android/text/style/IconMarginSpan#getPadding())`() ` Returns the padding width between the bitmap and the text.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` `[String](https://developer.android.com/reference/java/lang/String)        | ` `[toString](https://developer.android.com/reference/android/text/style/IconMarginSpan#toString())`() ` Returns a string representation of the object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](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 `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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`                                                                  | ` `[wait](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*.                                                                                             | ||
| From interface` `[android.text.style.LeadingMarginSpan](https://developer.android.com/reference/android/text/style/LeadingMarginSpan)` ` |------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[drawLeadingMargin](https://developer.android.com/reference/android/text/style/LeadingMarginSpan#drawLeadingMargin(android.graphics.Canvas,%20android.graphics.Paint,%20int,%20int,%20int,%20int,%20int,%20java.lang.CharSequence,%20int,%20int,%20boolean,%20android.text.Layout))`(`[Canvas](https://developer.android.com/reference/android/graphics/Canvas)` c, `[Paint](https://developer.android.com/reference/android/graphics/Paint)` p, int x, int dir, int top, int baseline, int bottom, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, int start, int end, boolean first, `[Layout](https://developer.android.com/reference/android/text/Layout)` layout) ` Renders the leading margin. | | ` abstract int`  | ` `[getLeadingMargin](https://developer.android.com/reference/android/text/style/LeadingMarginSpan#getLeadingMargin(boolean))`(boolean first) ` Returns the amount by which to adjust the leading margin.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | ||
| From interface` `[android.text.style.LineHeightSpan](https://developer.android.com/reference/android/text/style/LineHeightSpan)` ` |------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[chooseHeight](https://developer.android.com/reference/android/text/style/LineHeightSpan#chooseHeight(java.lang.CharSequence,%20int,%20int,%20int,%20int,%20android.graphics.Paint.FontMetricsInt))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, int start, int end, int spanstartv, int lineHeight, `[Paint.FontMetricsInt](https://developer.android.com/reference/android/graphics/Paint.FontMetricsInt)` fm) ` Classes that implement this should define how the height is being calculated. | ||

## Public constructors

### IconMarginSpan

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

```
public IconMarginSpan (Bitmap bitmap)
```

Creates an[IconMarginSpan](https://developer.android.com/reference/android/text/style/IconMarginSpan)from a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap).

<br />

|                                                Parameters                                                 ||
|----------|-------------------------------------------------------------------------------------------------|
| `bitmap` | `Bitmap`: bitmap to be rendered at the beginning of the text This value cannot be`null`. <br /> |

### IconMarginSpan

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

```
public IconMarginSpan (Bitmap bitmap, 
                int pad)
```

Creates an[IconMarginSpan](https://developer.android.com/reference/android/text/style/IconMarginSpan)from a[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap).

<br />

|                                                Parameters                                                 ||
|----------|-------------------------------------------------------------------------------------------------|
| `bitmap` | `Bitmap`: bitmap to be rendered at the beginning of the text This value cannot be`null`. <br /> |
| `pad`    | `int`: padding width, in pixels, between the bitmap and the text Value is 0 or greater <br />   |

## Public methods

### chooseHeight

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

```
public void chooseHeight (CharSequence text, 
                int start, 
                int end, 
                int istartv, 
                int v, 
                Paint.FontMetricsInt fm)
```

Classes that implement this should define how the height is being calculated.

<br />

|                                    Parameters                                    ||
|-----------|-----------------------------------------------------------------------|
| `text`    | `CharSequence`: the text <br />                                       |
| `start`   | `int`: the start of the line <br />                                   |
| `end`     | `int`: the end of the line <br />                                     |
| `istartv` | `int`: the start of the span <br />                                   |
| `v`       | `int`: the line height <br />                                         |
| `fm`      | `Paint.FontMetricsInt`: font metrics of the paint, in integers <br /> |

### drawLeadingMargin

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

```
public void drawLeadingMargin (Canvas c, 
                Paint p, 
                int x, 
                int dir, 
                int top, 
                int baseline, 
                int bottom, 
                CharSequence text, 
                int start, 
                int end, 
                boolean first, 
                Layout layout)
```

Renders the leading margin. This is called before the margin has been adjusted by the value returned by[getLeadingMargin(boolean)](https://developer.android.com/reference/android/text/style/LeadingMarginSpan#getLeadingMargin(boolean)).

<br />

|                                                                    Parameters                                                                    ||
|------------|--------------------------------------------------------------------------------------------------------------------------------------|
| `c`        | `Canvas`: the canvas <br />                                                                                                          |
| `p`        | `Paint`: the paint. The this should be left unchanged on exit. <br />                                                                |
| `x`        | `int`: the current position of the margin <br />                                                                                     |
| `dir`      | `int`: the base direction of the paragraph; if negative, the margin is to the right of the text, otherwise it is to the left. <br /> |
| `top`      | `int`: the top of the line <br />                                                                                                    |
| `baseline` | `int`: the baseline of the line <br />                                                                                               |
| `bottom`   | `int`: the bottom of the line <br />                                                                                                 |
| `text`     | `CharSequence`: the text <br />                                                                                                      |
| `start`    | `int`: the start of the line <br />                                                                                                  |
| `end`      | `int`: the end of the line <br />                                                                                                    |
| `first`    | `boolean`: true if this is the first line of its paragraph <br />                                                                    |
| `layout`   | `Layout`: the layout containing this line <br />                                                                                     |

### getBitmap

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

```
public Bitmap getBitmap ()
```

Returns the bitmap to be used at the beginning of the text

<br />

|                                                        Returns                                                         ||
|---------------------------------------------------------------------------|---------------------------------------------|
| [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap) | a bitmap This value cannot be`null`. <br /> |

### getLeadingMargin

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

```
public int getLeadingMargin (boolean first)
```

Returns the amount by which to adjust the leading margin. Positive values move away from the leading edge of the paragraph, negative values move towards it.

<br />

|                                                   Parameters                                                    ||
|---------|--------------------------------------------------------------------------------------------------------|
| `first` | `boolean`: true if the request is for the first line of a paragraph, false for subsequent lines <br /> |

|                 Returns                  ||
|-------|-----------------------------------|
| `int` | the offset for the margin. <br /> |

### getPadding

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

```
public int getPadding ()
```

Returns the padding width between the bitmap and the text.  
The units of this value are pixels.

<br />

|                                   Returns                                   ||
|-------|----------------------------------------------------------------------|
| `int` | a padding width in pixels The units of this value are pixels. <br /> |

### toString

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

```
public String toString ()
```

Returns a string representation of the object.

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------|-----------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | a string representation of the object. <br /> |