Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"

like image 919
hasen Avatar asked Feb 15 '26 03:02

hasen


1 Answers

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..

like image 71
Nikhil Borad Avatar answered Feb 16 '26 18:02

Nikhil Borad