So I'd like to change the android:fontFamily
in Android but I don't see any pre-defined fonts in Android. How do I select one of the pre-defined ones? I don't really need to define my own TypeFace but all I need is something different from what it shows right now.
<TextView
android:id="@+id/HeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp"
android:gravity="center"
android:text="CallerBlocker"
android:textSize="40dp"
android:fontFamily="Arial"
/>
It seems what I did up there won't really work! BTW android:fontFamily="Arial"
was a stupid attempt!
I had to parse
/system/etc/fonts.xml
in a recent project. Here are the current font families as of Lollipop:Here is the parser (based off FontListParser):
Feel free to use the above class in your project. For example, you could give your users a selection of font families and set the typeface based on their preference.
A small incomplete example:
You can do it easy way by using following library
https://github.com/sunnag7/FontStyler
its light weight and easy to implement, just copy your fonts in asset folder and use name in xml.
I use Letter Press lib for my NonTextView stuff like Buttons and kianoni fontloader lib for my TextViews cause of usage of style in this lib is more easy than Letter Press for me and i got ideal feedback with that. this is great for those who want to use custom font except Roboto Font. so it was my experience with font libs. for those who want to use custom class for change font i highly recommended to create this class with this snippet
And use class like this :
maybe this help.
It's the same as
android:typeface
.built-in fonts are:
See android:typeface.
With some trial and error I learned the following.
Within the *.xml you can combine the stock fonts with the following functions, not only with typeface:
With this two styles, there was no need to use typeface in any other case. The range of combinations is much more bigger with fontfamily&textStyle.
Here you can see all the avaliable fontFamily values and it's corresponding font file's names(This file is using in android 5.0+). In mobile device, you can find it in:
(For android 4.4 and below using this version, but I think that
fonts.xml
has a more clear format and easy to understand.)For example,
The name attribute
name="sans-serif"
offamily
tag defined the value you can use in android:fontFamily.The
font
tag define the corresponded font files.In this case, you can ignore the source under
<!-- fallback fonts -->
, it's using for fonts' fallback logic.