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 the TextView
that you want indirectly, because it seems that this TextView
has no id, like this:
Toolbar toolbar = (Toolbar) findViewById(R.id.action_bar);
TextView textView = (TextView) toolbar.getChildAt(0);
I used the Hierarchy Viewer tool to get the view tree. (Tool that you can find into Android Device Monitor under Hierarchy View perspective)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With