4

I have one Activity that get ActionBar title from ListView position in other activity and I want set Typeface in ActionBar.

package com.cambobox.actionbartitle.actionbar;

import android.app.ActionBar;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.TypefaceSpan;
import android.widget.TextView;

public class Song extends ActionBarActivity {
Typeface font;
@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_song);
   font = Typeface.createFromAsset(getAssets(),"fonts/khmerbibleregular.ttf");
   Intent intent = getIntent();
   String listview_id = intent.getStringExtra(SongList.NAME);
   ActionBar actionnbar_title = getActionBar();
   actionnbar_title.setDisplayShowTitleEnabled(true);
   actionnbar_title.setTitle(font);
   actionnbar_title.setTitle(listview_id);
}
}
Lavekush Agrawal
  • 6,040
  • 7
  • 52
  • 85
user3242962
  • 105
  • 1
  • 7

1 Answers1

0

It is a bit of a hack, but it works.

protected void onCreate(Bundle savedInstanceState) {
    ...
    int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
    TextView textView = (TextView) findViewById(titleId);
    Typeface typeface = Typeface.create("sans-serif-light", Typeface.ITALIC); // add your typeface
    textView.setTypeface(typeface);
    ...
}
Blaz
  • 1,935
  • 15
  • 14