Reputation: 41
I am trying to change the text appearance of the title bar im using on my activity. In depth: i want to change the fontFamily to sans-serif-thin.
This is what i tried to do among various other approaches:
<style name="CustomActionBarTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/jammi_red</item>
<item name="colorPrimaryDark">@color/jammi_red_dark</item>
<item name="colorAccent">@color/jammi_green</item>
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
</style>
<style name="myTheme.ActionBar.Text" parent="Base.TextAppearance.AppCompat.Title">
<item name="android:fontFamily">sans-serif-thin</item>
</style>
Does anyone know what im doing wrong? I'm working on a Nexus 5 with API 21. Minimum API for my App is 16.
Upvotes: 0
Views: 547
Reputation: 3471
This is how I did this in my app. This is part of my MainActivity code:
Typeface face=Typeface.createFromAsset(getAssets(),"fonts/CustomFont.ttf");
actionBar = getSupportActionBar();
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
TextView tv = (TextView) findViewById(titleId);
tv.setTypeface(face);
Don't forget to put your .ttf file into the asset folder.
Upvotes: 1
Reputation: 1076
You said your minimum sdk level is 16, so do not use the AppCompat
package, it is for older versions for backward compatability. Use one of the platform themes such as Theme.Holo.Light.Dark.ActionBar
that does have not the AppCompat
in it as the parent.
Upvotes: 0
Reputation: 1166
Try to do it programmatically (put your Typeface file in asset folder), it works for me:
int titleId = getResources().getIdentifier("action_bar_title", "id","android");
TextView yourTextView = (TextView) findViewById(titleId);
private Typeface tfLogo = Typeface.createFromAsset(getAssets(), "font/Wolf.otf");
yourTextView.setTypeface(tfLogo);
Upvotes: 0