I have added a custom font file to my assets/fonts folder. How do I use it from my XML?
I can use it from code as follows:
TextView text =
I know this is an old question, but i've found a much easier solution.
First declare your TextView in xml as usual. Put your font (TTF or TTC) in the asset folder
app\src\main\assets\
Then just set the typeface for your text view in your onCreate method.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_name);
TextView textView = findViewById(R.id.my_textView);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fontName.ttf");
textView.setTypeface(typeface);
}
Done.