Added in API level 1

QuoteSpan


open class QuoteSpan : LeadingMarginSpan, ParcelableSpan
kotlin.Any
   ↳ android.text.style.QuoteSpan

A span which styles paragraphs by adding a vertical stripe at the beginning of the text (respecting layout direction).

A QuoteSpan must be attached from the first character to the last character of a single paragraph, otherwise the span will not be displayed.

QuoteSpans allow configuring the following elements:

  • color - the vertical stripe color. By default, the stripe color is 0xff0000ff
  • gap width - the distance, in pixels, between the stripe and the paragraph. Default value is 2px.
  • stripe width - the width, in pixels, of the stripe. Default value is 2px.
For example, a QuoteSpan using the default values can be constructed like this:
<code>SpannableString string = new SpannableString("Text with quote span on a long line");
 string.setSpan(new QuoteSpan(), 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</code>
QuoteSpan constructed with default values.

To construct a QuoteSpan with a green stripe, of 20px in width and a gap width of 40px:

<code>SpannableString string = new SpannableString("Text with quote span on a long line");
 string.setSpan(new QuoteSpan(Color.GREEN, 20, 40), 0, string.length(),
 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);</code>
Customized QuoteSpan.

Summary

Constants
static Int

Default color for the quote stripe.

static Int

Default gap width in pixels.

static Int

Default stripe width in pixels.

Public constructors

Creates a QuoteSpan with the default values.

Create a QuoteSpan from a parcel.

QuoteSpan(color: Int)

Creates a QuoteSpan based on a color.

QuoteSpan(color: Int, stripeWidth: Int, gapWidth: Int)

Creates a QuoteSpan based on a color, a stripe width and the width of the gap between the stripe and the text.

Public methods
open Int

open Unit
drawLeadingMargin(c: Canvas, p: Paint, x: Int, dir: Int, top: Int, baseline: Int, bottom: Int, text: CharSequence, start: Int, end: Int, first: Boolean, layout: Layout)

Renders the leading margin.

open Int

Get the color of the quote stripe.

open Int

Get the width of the gap between the stripe and the text.

open Int

open Int

open Int

Get the width of the quote stripe.

open String

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

Constants

STANDARD_COLOR

Added in API level 28
static val STANDARD_COLOR: Int

Default color for the quote stripe.

Value: -16776961

STANDARD_GAP_WIDTH_PX

Added in API level 28
static val STANDARD_GAP_WIDTH_PX: Int

Default gap width in pixels.

Value: 2

STANDARD_STRIPE_WIDTH_PX

Added in API level 28
static val STANDARD_STRIPE_WIDTH_PX: Int

Default stripe width in pixels.

Value: 2

Public constructors

QuoteSpan

Added in API level 1
QuoteSpan()

Creates a QuoteSpan with the default values.

QuoteSpan

Added in API level 3
QuoteSpan(src: Parcel)

Create a QuoteSpan from a parcel.

Parameters
src Parcel: This value cannot be null.

QuoteSpan

Added in API level 1
QuoteSpan(color: Int)

Creates a QuoteSpan based on a color.

Parameters
color Int: the color of the quote stripe.

QuoteSpan

Added in API level 28
QuoteSpan(
    color: Int,
    stripeWidth: Int,
    gapWidth: Int)

Creates a QuoteSpan based on a color, a stripe width and the width of the gap between the stripe and the text.

Parameters
color Int: the color of the quote stripe.
stripeWidth Int: the width of the stripe. Value is 0 or greater
gapWidth Int: the width of the gap between the stripe and the text. Value is 0 or greater

Public methods

describeContents

Added in API level 3
open fun describeContents(): Int
Return
Int 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

drawLeadingMargin

Added in API level 1
open fun drawLeadingMargin(
    c: Canvas,
    p: Paint,
    x: Int,
    dir: Int,
    top: Int,
    baseline: Int,
    bottom: Int,
    text: CharSequence,
    start: Int,
    end: Int,
    first: Boolean,
    layout: Layout
): Unit

Renders the leading margin. This is called before the margin has been adjusted by the value returned by getLeadingMargin(boolean).

Parameters
c Canvas: This value cannot be null.
p Paint: This value cannot be null.
x Int: the current position of the margin
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.
top Int: the top of the line
baseline Int: the baseline of the line
bottom Int: the bottom of the line
text CharSequence: This value cannot be null.
start Int: the start of the line
end Int: the end of the line
first Boolean: true if this is the first line of its paragraph
layout Layout: This value cannot be null.

getColor

Added in API level 1
open fun getColor(): Int

Get the color of the quote stripe.

Return
Int the color of the quote stripe.

getGapWidth

Added in API level 28
open fun getGapWidth(): Int

Get the width of the gap between the stripe and the text.

Return
Int the width of the gap between the stripe and the text.

getLeadingMargin

Added in API level 1
open fun getLeadingMargin(first: Boolean): Int
Parameters
first Boolean: true if the request is for the first line of a paragraph, false for subsequent lines
Return
Int the offset for the margin.

getSpanTypeId

Added in API level 3
open fun getSpanTypeId(): Int

getStripeWidth

Added in API level 28
open fun getStripeWidth(): Int

Get the width of the quote stripe.

Return
Int the width of the quote stripe.

toString

Added in API level 1
open fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 3
open fun writeToParcel(
    dest: Parcel,
    flags: Int
): Unit
Parameters
dest Parcel: The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES