I tried to set custom font to ActionBar title: How to Set a Custom Font in the ActionBar Title?. So in Activity onCreate
:
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
TextView yourTextView = (TextView) findViewById(titleId);
yourTextView.setTextColor(getResources().getColor(R.color.black));
yourTextView.setTypeface(face);
but findViewById
returns null
. Why?
I'm using support library:
import android.support.v7.app.ActionBarActivity;
It seems that's broken in Lollipop. Don't know if there's a best alternative but you can do something like this, if you're using Toolbar:
And on your activity:
I had a similar problem while trying to set a content description for action bar title, using the support libs. The answer here works for me: how to reference ActionBar title View on Lollipop
You can retrieve the TextView that you want indirectly, because the title TextView has no resource id, like this: