Android custom fonts (nunito) not set properly in TextView

Viewed 1451

I am using custom fonts in my android TextView.

Typeface tf = Typeface.createFromAsset(getAssets(),
                "nunitomedium.ttf");
        txt2= (TextView) findViewById(R.id.txt2);
        txt2.setTypeface(tf);

But padding between lines are not properly show.

<TextView
        android:id="@+id/txt2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/_10sdp"
        android:layout_marginRight="@dimen/_10sdp"
        android:layout_marginTop="@dimen/_15sdp"
        android:text="You can send emergency blast to friends and family whenever you feel uncomfortable. Once activated, you will be able to send an emergency blast to your safety network within seconds with the pressing of one button."
        android:textColor="@color/colorBlack"
        android:textSize="@dimen/_15sdp" />

Here is my output :

enter image description here

I also tried with following code :

android:includeFontPadding="false"

but still same issue. Not sure but I also tried to use justifyTextView from Here but same issue. Does anybody faced same issue before?

Thanks in advance.

EDIT :

If i use android:lineSpacingExtra 1st line have more space then other lines. Here is my code and output.

<TextView
        android:id="@+id/txt2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/_10sdp"
        android:layout_marginRight="@dimen/_10sdp"
        android:layout_marginTop="@dimen/_15sdp"
        android:lineSpacingExtra="@dimen/_5sdp" <<<<<<<
        android:text="You can send emergency blast to friends and family whenever you feel uncomfortable. Once activated, you will be able to send an emergency blast to your safety network within seconds with the pressing of one button."
        android:textColor="@color/colorBlack"
        android:textSize="@dimen/_15sdp" />

enter image description here

3 Answers

Late to the party on this - we had exactly the same issue, was fixed completely by replacing the .ttf font file with the latest from Google Fonts - there's a bad early version of this font doing the rounds. Don't forget to remove any android:lineSpacingMultiplier fudges you've put in place int he meanwhile.

Related