简体   繁体   English

如何在Android中为TabView设置颜色?

[英]How do I set the color for a tabview in android?

I want to change the colour of a tabview from the default grey (and black when not selected) to red and green when not selected. 我想将Tabview的颜色从默认的灰色(未选择时为黑色)更改为未选择时的红色和绿色。

In the tab Widget class I'm trying to set the colour using these functions 在标签Widget类中,我试图使用这些功能设置颜色

tabHost.setBackgroundColor(Color.RED);
tabHost.getTabWidget().setBackgroundColor(Color.GREEN);

But they don't work, its still the default colour. 但是它们不起作用,它仍然是默认颜色。 How do I manually set the background and tab colours of a tab widget in android? 如何在android中手动设置标签小部件的背景和标签颜色? Also, is it possible to do it in xml? 另外,有可能在xml中完成吗?

See Step 4. at this blog, it's how I have done it, very simple, easy to change and tweak if you need to and it's all in XML. 请参阅此博客上的步骤4。这就是我的操作方式,非常简单,易于更改和调整(如果需要),而且全部以XML编写。

Custom tabs in android tabhost android tabhost中的自定义标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM