Search code examples
androidkotlincustom-fonttypeface

Android: vertical space around text with custom typeface


I downloaded some fonts from the Noto font family, put them in the assets folder, and loaded them into a Typeface object, and then I programmatically set the typeface on a TextView, but when I do that there's some extra vertical padding above and below the text. It's as if the text height or line height was changed.

Note that I'm using Kotlin/Anko, so the syntax might look weird compared to regular Java/XML:

textView {
    text = someSpannableString
    padding = dip(10)
    isSelectable = true
    typeface = someTypefaceInstance
}

I tried to do this:

setLineSpacing(0f, 1f)

But it did not change anything.

For what it's worth, the particular typeface here is "NotoSerifCJKjp-Regular.otf"


Solution

  • try with this in xml

    android:includeFontPadding="false"
    android:lineSpacingExtra="0dp"
    

    includeFontPadding removes the padding reserved for accents and lineSpacingExtra removes the space between two lines of text.

    Hope it helps..