如何更改操作栏标题颜色在code如何更改、颜色、操作、标题

2023-09-12 01:14:57 作者:傾盡壹生為紅顏

我无法改变机器人的操作栏标题颜色编程为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);