Android examples for User Interface:ActionBar Title
Change title in the ActionBar
import android.app.Activity; import android.support.v4.app.Fragment; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; import android.text.Spannable; import android.text.SpannableString; import android.text.TextUtils; import android.view.View; import android.widget.ProgressBar; public class Main{ /**//from w ww. j av a2s . co m * Change title in the ActionBar * @param activity activity * @param title title of ActionBar */ public static void changeActionBarTitle(Activity activity, String title) { changeActionBarTitle(activity, title, null); } /** * Change title in the ActionBar * @param activity activity * @param title title of ActionBar * @param typefaceName the full path to font in the assets */ public static void changeActionBarTitle(Activity activity, String title, String typefaceName) { if (activity == null) return; if (!(activity instanceof ActionBarActivity)) return; ActionBar actionBar = ((ActionBarActivity) activity) .getSupportActionBar(); if (actionBar != null) { if (title != null) { if (!TextUtils.isEmpty(typefaceName)) { SpannableString spannableTitle = new SpannableString( title); spannableTitle.setSpan(new TypefaceSpan(activity, typefaceName), 0, spannableTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); actionBar.setTitle(spannableTitle); } else { actionBar.setTitle(title); } } } } }