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 am using excellent library Calligraphy by Chris Jenx designed to allow you to use custom fonts in your android application. Give it a try!
To set Roboto programmatically:
I just want to mention that the hell with the fonts inside Android is about to end, because this year on Google IO we finally got this -> https://developer.android.com/preview/features/working-with-fonts.html
Now there is a new resource type a font and you can place all your application fonts inside res/fonts folder and access then with R.font.my_custom_font, just like you can access string res values, drawable res values etc. You have even chance to create font-face xml file, which is gonna be set of your custom fonts (about italic, bold and underline attr).
Read the link above for more info. Let's see the support.
You set style in
res/layout/value/style.xml
like that:and to use this style in
main.xml
file use:From android 4.1 / 4.2 / 5.0, the following Roboto font families are available:
in combination with
this 16 variants are possible:
fonts.xml