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\'
There is a nice library available for this
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
It's the same as android:typeface
.
built-in fonts are:
See android:typeface.
If you are using Android Studio 3.5+, Changing font is super simple. Select the text widget on Design view and check fontFamily on Attribute Window. The value dropdown contains all the available fonts from which you can select one. If you are looking for Google Fonts, Click More Fonts option.
Attribute Window
Google Fonts
Try this:
TextView textview = (TextView) findViewById(R.id.textview);
Typeface tf= Typeface.createFromAsset(getAssets(),"fonts/Tahoma.ttf");
textview .setTypeface(tf);
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.
The easiest way to add the font programatically to a TextView is to, first, add the font file in your Assets folder in the project. For example your font path is looking like this: assets/fonts/my_font.otf
And add it to a TextView as:
Kotlin
val font_path = "fonts/my_font.otf"
myTypeface = Typeface.createFromAsset(MyApplication.getInstance().assets, font_path)
textView.typeface = myTypeface
Java
String font_path = "fonts/my_font.otf";
Typeface myTypeface = Typeface.createFromAsset(MyApplication.getInstance().assets, font_path)
textView.setTypeface(myTypeface);