My question is i want to change font of action bar without making custom layout for action bar like implment text view and then apply typeface on that text view because i want to too subtitle bar text so what is solution for it
Asked
Active
Viewed 208 times
0
-
Do you want to change the font of only the title? – Apoorv May 15 '14 at 09:40
-
i want to set font on title and subtitle too.. – May 15 '14 at 09:41
3 Answers
1
You can use SpannableString
with a custom TypeFaceSpan (https://stackoverflow.com/a/4826885/1785133) for actionBar title and subtitle.
SpannableString sbTitle = new SpannableString(getTitle());
Typeface typeface = Typeface.createFromAsset(getAssets(), "custom.ttf"); //cache it
sbTitle.setSpan(new CustomTypefaceSpan("custom", typeface), 0, sbTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
getActionBar().setTitle(sbTitle);
0
You can do something like
SpannableString localSpannableString = new SpannableString("Penguin");
localSpannableString.setSpan(new TypefaceSpan(MainActivity.this, "PreludeFLF-BoldItalic.ttf"), 0, localSpannableString.length(), 33);
ActionBar localActionBar = getSupportActionBar();
localActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#81D2F0")));
localActionBar.setTitle(localSpannableString);

Apoorv
- 13,470
- 4
- 27
- 33
-1
Try following code in onCreate()
int titleId = getResources().getIdentifier("action_bar_title", "id",
"android");
TextView txtTitle = (TextView) findViewById(titleId);
txtTitle.setTextColor(getResources().getColor(R.color.title_color));
txtTitle.setTypeface((Typeface.createFromAsset(this.getAssets(),"FuturaBoldBT.ttf")));
Hope this helps

Aman Systematix
- 347
- 2
- 10
-
Using `getResources().getIdentifier("action_bar_title", "id", "android")` is a bad way to do it. – flav May 15 '14 at 09:58
-
-
thats ryt but, there are not any solution for set custom font on actionbar title – May 15 '14 at 10:15
-
@Pranav I gave you one. The idea is to set a "decorated" String (aka `SpannableString`) instead of a String. It works with setTitle and setSubtitle. – flav May 15 '14 at 10:18