6

In attempting to modify the font of my ActionBar title I located an answer which suggested adjusting the Typeface via a SpannableString. While it works as noted in the answer, the placement seems to deviate from being vertically centered.

screenshot of title not vertically centered

I have tried this with two different fonts, both OpenType (Roundhand) and TrueType (Billabong). In addition I have tried this on an older Gingerbread device (where the screenshot is from) running 2.3.3 as well as a via a newer Jelly Bean device running 4.2. The project makes use of ActionBarSherlock and thus is my last theoretical culprit. I have also adjusted the font size in hopes of it centering slightly but know that this is nothing more than a hack and is not solving the ultimate problem at hand.

With that, why is my title not centered appropriately and how can I correct it? If there is a way to adjust the alignment per the implemented solution referenced above that would certainly suffice, even if ActionBarSherlock is the culprit. Knowing what the culprit is and why this is occurring however is part of the answer, not just providing a workaround.

UPDATE:

Screenshot below making use of Show layout bounds. Please note that in order to make use of the Show layout bounds that this device is obviously running Jelly Bean whereas the previous screenshot was from a Gingerbread device. In either case, the problem is the same.

enter image description here

UPDATE:

If I use Typeface.DEFAULT when I call setSpan the bounds and alignment appear as they should.

enter image description here

UPDATE:

Upon trying a third font, it appears the issue is in fact tied to the fonts.

enter image description here

Community
  • 1
  • 1
Aaron McIver
  • 24,527
  • 5
  • 59
  • 88

2 Answers2

0

This is going to sound really stupid but I've just spent 1 hour figuring out that I had a subtitle underneath the title which was set to the color of the action bar background so it was invisible.

Maybe that will help someone, somewhere :)

Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135
-1

If you have it set a custom view, you can go into the xml and set the gravity to centered.