I am trying to change the font of my application title. In order to do this, I decided to traverse through the toolbar, find the title TextView and then set the typeface.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView title = null;
View child = null;
for(int i=0; i < toolbar.getChildCount(); i++){
child = toolbar.getChildAt(i);
if(child instanceof TextView){
title = (TextView) child;
break;
}
}
Typeface logoFont = Typeface.createFromAsset(getAssets(),"fonts/font.ttf");
if(title!=null){
title.setTypeface(logoFont);
}
setSupportActionBar(toolbar);
But toolbar.getChildCount() is returning 0. Toolbar doesn't seem to have any children. Can someone help me with this?