How to Link to an ActionBar View Title on Lollipop

I have Activityone that extends AppCompatActivityand uses support ActionBar. Compile the SDK version is 23, the test device SDK - 21-22. I need to get the ActionBartitle TextView, however the most famous way to do it

int resId = getResources().getIdentifier("action_bar_title", "id", "android");
return (TextView) findViewById(resId);

not working starting with API 21. Is there a way to link to the header TextViewon Lollipop?

+4
source share
2 answers

C AppCompatActivityYou can get indirect TextView, because it seems that this one TextViewdoes not have an identifier, for example:

Toolbar toolbar = (Toolbar) findViewById(R.id.action_bar);
TextView textView = (TextView) toolbar.getChildAt(0);

Hierarchy Viewer, . (, Android- )

Action bar view tree

+7
+1

Source: https://habr.com/ru/post/1607687/


All Articles