Android custom fonts (nunito) are not installed properly in TextView

I use custom fonts in my android TextView.

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

But the spacing between the lines is not displayed properly.

<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 conclusion:

enter image description here

I also tried with the following code:

android:includeFontPadding="false"

but still the same question. Not sure, but I also tried to use justifyTextViewfrom Here , but the same problem. Has anyone encountered the same problem before?

Thanks in advance.

EDIT:

If I use android:lineSpacingExtra, the first line has more space than the 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

+4
source share
3 answers

- , , .ttf Google Fonts - , . android:lineSpacingMultiplier , .

+2

linespacingMultiplier XML

 <TextView
        android:id="@+id/textview_font"
        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="@android:color/black"
        android:lineSpacingMultiplier="3"
        android:textSize="@dimen/_15sdp" />

: -

 mTextViewFont=(TextView)findViewById(R.id.textview_font);
        Typeface tf = Typeface.createFromAsset(getAssets(),
                "nunitomedium.ttf");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mTextViewFont.setLineSpacing((float) 5.5,(float) 1.2);
        }
        mTextViewFont.setTypeface(tf);
0

, .

dafontfree.net/download-nunito-f92263.htm

.

.

enter image description here

0

Source: https://habr.com/ru/post/1677506/


All Articles