The problem I am having is specific to Android 5.0 (including 5.0.1/5.0.2) on both phones and my tablet (Nexus 9). Earlier versions of Android work fine.
In my app I want to set a global font that overrides all text. The way I've been accomplishing this prior to 5.0 was using this method. This method of font overriding doesn't seem work on any version of Lollipop that I've tried but works perfectly in 2.x and 4.x. I'm also running this code in a BaseApplication
class I have so the font is only initialized in the onCreate()
of my BaseApplication
.
It seems like this was a bug in the Developer Preview and reported here. I tried the fix suggested in post #16 to use the TTX Tool to convert your font file to .ttx and back to .otf but that didn't seem to fix the issue like it did for others. I also verified that my .otf font file is valid and isn't corrupted according to the OTS sanitizer tool.
I also have a custom TextView that I can set the font via the layout. An example would be:
<com.myapp.widgets.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing text view font"
myapp:fontName="my-font.otf" />
This CustomTextView uses setTypeface(typeFace)
in the view's initialization to set the font. This works on 5.0 but isn't really a possible solution I can use since I would need to go through every layout and change TextView, EditText, etc to use the CustomTextView and doesn't work with Dialog text wither.
So setting a single TextView's font with my CustomTextView class works fine in all version of Android, just not setting it globally.
I've also looked through the styles source code to see if I can find any differences between the Material and Holo theme but nothing seemed like it would change the android:typeface
. My initial thoughts with this were that the Material theme somehow is overriding the android:typeface
attribute over my app theme but I wasn't able to find anything.
Any thoughts or input would be greatly appreciated, thanks!