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.
在尝试修改我的ActionBar标题的字体时,我找到了一个答案,建议通过SpannableString调整字体。虽然它的工作原理如答案中所述,但放置似乎偏离垂直居中。
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.
我尝试过两种不同的字体,包括OpenType(Roundhand)和TrueType(Billabong)。此外,我在一台较旧的Gingerbread设备(屏幕截图来自)上运行2.3.3以及通过运行4.2的较新的Jelly Bean设备试用了这个。该项目使用ActionBarSherlock,因此是我最后的理论罪魁祸首。我也调整了字体大小,希望它略微集中,但要知道这只不过是一个黑客,并没有解决手头的最终问题。
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.
有了这个,为什么我的标题没有适当集中,我该如何纠正呢?如果有一种方法可以调整上面引用的实现解决方案的对齐方式,那肯定就足够了,即使ActionBarSherlock是罪魁祸首。然而,知道罪魁祸首是什么以及为什么会发生这种情况是答案的一部分,而不仅仅是提供一种解决方法。
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.
下面的截图使用了Show layout bounds。请注意,为了使用Show布局边界,该设备显然正在运行Jelly Bean,而之前的截图来自Gingerbread设备。在任何一种情况下,问题都是一样的。
UPDATE:
If I use Typeface.DEFAULT
when I call setSpan
the bounds and alignment appear as they should.
如果我在调用setSpan时使用Typeface.DEFAULT,那么边界和对齐就会出现。
UPDATE:
Upon trying a third font, it appears the issue is in fact tied to the fonts.
在尝试第三种字体时,问题似乎与字体有关。
2 个解决方案
#1
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.
这听起来真的很愚蠢,但我花了1个小时搞清楚我在标题下面有一个字幕,它设置为动作栏背景的颜色,所以它是看不见的。
Maybe that will help someone, somewhere :)
也许这会帮助某人,某处:)
#2
-1
If you have it set a custom view, you can go into the xml and set the gravity to centered.
如果您设置了自定义视图,则可以进入xml并将重力设置为居中。
#1
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.
这听起来真的很愚蠢,但我花了1个小时搞清楚我在标题下面有一个字幕,它设置为动作栏背景的颜色,所以它是看不见的。
Maybe that will help someone, somewhere :)
也许这会帮助某人,某处:)
#2
-1
If you have it set a custom view, you can go into the xml and set the gravity to centered.
如果您设置了自定义视图,则可以进入xml并将重力设置为居中。