Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:lineSpacingMultiplier doesn't work in android:textAppearance

I'm trying to add android:lineSpacingMultiplier in my textAppearance style (android:textAppearance), and it's not working. Am I doing something wrong?

TextAppearance style:

<style name="TextAppearance.Body1" parent="TextAppearance.AppCompat.Body1">
      <item name="android:lineSpacingMultiplier">1.25</item>
</style> 

Use of style:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="This is body 1\nThis is body 1"
    android:textAppearance="TextAppearance.Body1"
    />
like image 253
loeschg Avatar asked Feb 13 '17 22:02

loeschg


People also ask

What is TextAppearance in Android?

TextAppearance allows you to define text-specific styling while leaving a View 's style available for other uses. Note, however, that if you define any text attributes directly on the View or in a style, those values would override the TextAppearance values.

How do I reduce the space between lines in Android?

Just we need to add an attribute with your TextView that give the spacing with lines. These are –android:lineSpacingExtra, android:lineSpacingMultiplier – use these two attributes with your TextView in XML file. or Programatically call setter method of that attribute textView. setLineSpacing().


1 Answers

For whatever reason android:lineSpacingMultiplier doesn't work as an item within your textAppearance. You'll either have to set it directly as a TextView attribute (using android:lineSpacingMultiplier), or create a regular style which "wraps" setting the textAppearance and lineSpacingMultiplier

Create a style

<style name="TextBody1">
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Body1</item>
    <item name="android:lineSpacingMultiplier">1.25</item>
</style>

or

<style name="TextBody1" parent="TextAppearance.AppCompat.Body1">
    <item name="android:lineSpacingMultiplier">1.25</item>
</style>

and then apply via style instead of android:textAppearance

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="This is body 1\nThis is body 1"
    style="@style/TextBody1"
    />
like image 167
loeschg Avatar answered Sep 17 '22 21:09

loeschg