0

How I can set a custom font as an application font? Here is my setup:

  1. The custom font is located in /assets/fonts/Calibri.TTF
  2. In my manifest, I set the application theme like so: android:theme="@style/AppTheme"
  3. Here is my style.xml:

<resources> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> <item name="android:typeface">Calibri.ttf</item> </style> </resources>

Now I cannot run this app. When I try to compile it, I a get an error like this:

error: Error: String types not allowed (at 'android:typeface' with value 'Calibri.ttf')
KevinOrr
  • 1,663
  • 3
  • 13
  • 24
SHIDHIN TS
  • 1,557
  • 3
  • 26
  • 58
  • You cannot apply in style...try this way in java code. http://stackoverflow.com/a/13539825/1608643 – Ketan Ahir Jul 10 '14 at 05:58
  • @KetanAhir SO How can I set a font as application font. – SHIDHIN TS Jul 10 '14 at 06:02
  • create custom TextView and use it in your app. http://stackoverflow.com/questions/4395309/android-want-to-set-custom-fonts-for-whole-application-not-runtime/9199258#9199258 – Ketan Ahir Jul 10 '14 at 06:05

3 Answers3

2

typeface value should be like these values. "normal,sans,serif,monospace"

Hideme Sri
  • 193
  • 9
1

You need to rename your customs fonts from Calibri.ttf to calibri.ttf

and secondly you can't directly give fonts in resource file

try to refer this on github

https://gist.github.com/artem-zinnatullin/7749076

Suraj Pohwani
  • 138
  • 1
  • 9
0

Yes with reflection. This works have a look on following stackoverflow question Is it possible to set a custom font for entire of application?

Community
  • 1
  • 1
Ashwini
  • 136
  • 1
  • 8