Search code examples
androidandroid-actionbar-compatspannable

ActionBar title with compound drawable


is it possible to the add a compound drawable (something like drawableLeft) to the standard action bar title without using a custom view?

Atm i am using a SpannableString for the title (in order to use a custom typeface). If I can't set a compund drawable would it be possible to use an ImageSpan that i could append to my SpannableString?

Thx


Solution

  • Yep, absolutely. Here's a quick example:

        final int abTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
        final TextView abTitle = (TextView) findViewById(abTitleId);
        abTitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.your_icon, 0, 0, 0);