Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add font Family attribute under Attributes in the graphical layout android studio

I use android studio to create an android app. I use as an OS Ubuntu 14.04. In my app, I want to change the font, I follow the following step:

  1. Right-click in the res folder and go to New > Android resource directory.
  2. In the Resource type list, I select font, and then I click OK
  3. I add my font files in the font folder
  4. After that, in the layout xml I set the fontFamily attribute to the font file that I want to access as the following in textView component android:fontFamily="@font/cairo_extralight"

After that, the font doesn't change because we should change it also in the attributes of the graphical layout.But, when I go to the attributes in the graphical layout, I didn't found the fontfamily attribute under textAppearance property. I want to know why the fontfamily attribute does not exist in the list of proprety and how can I add it.

like image 927
Lina Avatar asked Dec 18 '25 06:12

Lina


1 Answers

Some common problems you should check:

  • android:fontFamily only works from API version 16. On Android versions below, the property will have no effect.
  • Support for using android:fontFamily with your own fonts was added in Support Library v26 and Android Studio 3.0 (together with Android Gradle Plugin version 3.0). If you are using older versions of any of these, it will not work.
  • If you have a custom TextView, make sure you extend AppCompatTextView. Otherwise no custom fonts will be used.
  • When using custom views, make sure that the attributes, theme, and style are correctly propagated (when overriding constructors for example).
  • Not all widgets support android:FontFamily. TextView, EditText, Button, and a few others do, but Checkbox and Switch don't. There you need to use setTypeFace in code instead.
like image 106
Daniel Zolnai Avatar answered Dec 19 '25 20:12

Daniel Zolnai