如何更改操作栏标题颜色在code [英] How to change action bar title color in code
本文介绍了如何更改操作栏标题颜色在code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法改变机器人的操作栏标题颜色编程为V11以上。我可以把它在XML完成,但需要动态地改变它在code。我应该怎么去呢?先谢谢了。
I'm having trouble changing androids action bar title color programmatically for v11 and up. I can get it done in xml but need to change it dynamically in code. How should I go about this? Thanks in advance.
推荐答案
在动作条
标题ID被隐藏,或者换句话说,它的内部和访问它不能被典型的做法。您可以使用它引用 Resources.getIdentifier
然后 View.findViewById
虽然。
The ActionBar
title ID is hidden, or in other words, it's internal and accessing it can't be done typically. You can reference it using Resources.getIdentifier
then View.findViewById
though.
抢ID为action_bar_title
int titleId = getResources().getIdentifier("action_bar_title", "id", "android");
现在,您可以用ID与的TextView
Now you can use the ID with a TextView
TextView abTitle = (TextView) findViewById(titleId);
abTitle.setTextColor(colorId);
这篇关于如何更改操作栏标题颜色在code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文