I'm looking for a way how I can change the font of the title in the actionbar before starting the main activity.
My current approach to change the font is the following:
int titleId = getResources().getIdentifier("action_bar_title", "id","android");
TextView textView = (TextView) findViewById(titleId);
textView .setTypeface(Typeface.createFromAsset(getAssets(), "my_font.ttf"));
This block of code is executed at the beginning of the onCreate method of the main activity. Actually, this works pretty well.
However, the small imperfection is only that when the application is launched, the title appears for a very short time in the default font before it changes. In my activity I use the DrawerLayout.
How can I change this behavior so that the text is displayed from the start in the right font?
Thank you for your help.
This is probably not possible. At least I have not found a way to accomplish this.
But I found a workaround that provides the same effect: You can design an image with the title and then define it in the styles.xml as the logo, for example:
...
<item name="android:logo">@drawable/ic_logo</item>
...
When the application is started up, the logo with the title can be removed again. As far as I've seen other apps (eg runtastic) use this technique as well.