I have an Activity
which extends the AppCompatActivity
and uses the support ActionBar
. Compile SDK version is 23, test devices SDK are 21-22.
I need to get the ActionBar
's title TextView
, however, the most known way of doing this
int resId = getResources().getIdentifier("action_bar_title", "id", "android");
return (TextView) findViewById(resId);
doesn't work starting with API 21. Is there a way to reference the title TextView
on Lollipop?
With
AppCompatActivity
, You can retrieve theTextView
that you want indirectly, because it seems that thisTextView
has no id, like this:I used the Hierarchy Viewer tool to get the view tree. (Tool that you can find into Android Device Monitor under Hierarchy View perspective)
Just some alternatives - you might consider defining your own custom textview to add to the toolbar if you wish to customize it - Adding custom view to a toolbar
Or extending
Toolbar
- findViewById returns null for action_bar_title