如何引用在棒棒堂动作条标题查看 [英] how to reference ActionBar title View on Lollipop

查看:216
本文介绍了如何引用在棒棒堂动作条标题查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有延伸的活动 AppCompatActivity ,并使用支持动作条。编译SDK版本是23,测试设备SDK是21-22。
我需要获得动作条的标题的TextView ,但是,这样做的最知名的方式

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);

不工作开始API 21.是否有引用标题的TextView 在棒棒糖的方法吗?

推荐答案

通过 AppCompatActivity ,您可以检索的TextView 要间接的,因为它似乎这个的TextView 没有ID,如下所示:

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);

我用层次浏览器工具来获取视图树。 (工具,你可以找到进入下层次视图的角度来看Android设备监视器)

I used the Hierarchy Viewer tool to get the view tree. (Tool that you can find into Android Device Monitor under Hierarchy View perspective)

操作栏视图树

这篇关于如何引用在棒棒堂动作条标题查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆