简体   繁体   中英

android custom fonts in xml

We can change fonts using java code as described here:

Roboto font in my android app

My question: Is there a way to specify the fonts in the xml layout file itself? Or better still, can we specify the font in the AndroidManifest.xml, so that it reflects across the app?

Thanks, Rahim.

You can use a theme that contains all the styles you want to use in your app (included fonts). The use of the schema is declared in the manifest

http://developer.android.com/guide/topics/ui/themes.html

If you want to manage custom fonts without headache, I suggest you to use a library that handles the hard part, like caching the fonts in memory and allows to preview the display in the Layout Editor. Then you can focus on creating the styles for your titles or texts.

I have done such a library called Smart Fonts for Android.

It is easy to install with gradle, and it is well documented.

It is available on GitHub:

https://github.com/smart-fun/SmartFonts

enjoy!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM