I would like to apply custom font to the title of my app which is displayed on the ActionBar. Previously I didn't use any support library and this solution:
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView yourTextView = (TextView) findViewById(titleId);
yourTextView.setTypeface(face);
worked fine for me. But now I am using material design SupportActionBar and this throws NullPointerException. So how to change the ActionBar font when using AppCompat?
Assuming you are already successfully using the new toolbar of AppCompat v22+ and that you are importing android.support.v7.widget.Toolbar in your activity.
So on your OnCreate you should already have
at this point you are almost done:
import java.lang.reflect.field;
and add following lines:
Use Toolbar instead of ActionBar.follow below steps to add toolbar: 1.change your app theme to
Theme.AppCompat.Light.NoActionBar
2.Goto project structure from File menu,goto library dependencies,add design library and sync your project. 3.Goto your layout where you want to display ActionBar and write below code:4.In the Activity,write as below:
To customize your title font:
Try this out Hopes this helps you,if anything wrong please let me know.
prepare Custom Layout ,put text view in action_bar_layout and then call actionbar.setcustomlayout()