BVB
BVB

Reputation: 5420

How to fix font baseline in Android Lollipop when working with custom icon fonts?

I am currently using FontAwesome in one of my Android projects. I primarily use it to display icons to the left of text on certain buttons. I noticed that since upgrading one of my test devices to Lollipop, the icons began sagging below the baseline of the text on the button. Please see the images below:

Android KitKat (Nexus 7) - good:

KitKat

Android Lollipop (Nexus 4) - bad:

Lollipop

Please note that the bottom of the icon in the first image sits on the baseline of the text, while the bottom of the icon in the second image is below the baseline.

Code:

<string name="button_text_logout"> LOG OUT</string>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:textSize="@dimen/text_size_menu_item"
    android:textColor="@color/white"
    android:gravity="center_vertical"
    android:text="@string/button_text_logout"
    android:paddingLeft="@dimen/action_item_padding"
    android:paddingRight="@dimen/action_item_padding"/>

Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf");
logOutTextView.setTypeface(typeface);

I am using the fa-sign-out icon. The code works fine on all devices running versions of Android prior to 5.0. Is there any way to fix this?

Upvotes: 6

Views: 1564

Answers (1)

QAMAR
QAMAR

Reputation: 2694

late but may help someone, Once resolved this issue using android:includeFontPadding="false"

Upvotes: 3

Related Questions