I'm using Toolbar from android v7 support library. I need to set up custom font for toolbars title text using theme. Can someone please provide working example how to do that using Calligraphy (https://github.com/chrisjenx/Calligraphy) Thanks
1 Answers
2
votes
I found that the current version of Calligraphy didn't work for me. I used the following method:
public static void applyFontForToolbarTitle(Activity context){
Toolbar toolbar = (Toolbar) context.findViewById(R.id.app_bar);
for(int i = 0; i < toolbar.getChildCount(); i++){
View view = toolbar.getChildAt(i);
if(view instanceof TextView){
TextView tv = (TextView) view;
Typeface titleFont = Typeface.
createFromAsset(context.getAssets(), "fonts/customFont");
if(tv.getText().equals(context.getTitle())){
tv.setTypeface(titleFont);
break;
}
}
}
}