有没有办法在不使用状态列表的情况下以编程方式设置特定的 Tablayout.Tab 文本颜色?

编程入门 行业动态 更新时间:2024-10-19 06:22:06
本文介绍了有没有办法在不使用状态列表的情况下以编程方式设置特定的 Tablayout.Tab 文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

问题是如何更改单个 TabLayout.Tab 的文本颜色.理想情况下,我想遍历选项卡并根据相应 ViewPager 的片段中包含的信息更改它们的颜色.

The question is how to change a single TabLayout.Tab's text color. Ideally, I'd like to iterate over the tabs and change their color based on information contained on the fragment of a corresponding ViewPager.

推荐答案

最简单的方法是从指定的TabLayout.Tab中获取TextView,然后设置文本颜色使用TextView.SetTextColor(Color color),你可以这样做:

The easiest way is to get the TextView from a specified TabLayout.Tab and then set the text color using TextView.SetTextColor(Color color), which you can do as followed:

TabLayout tabLayout = new TabLayout(this);
int wantedTabIndex = 0;

TextView tabTextView = (TextView)(((LinearLayout)((LinearLayout)tabLayout.GetChildAt(0)).GetChildAt(wantedTabIndex)).GetChildAt(1));

var textColor = Color.Black;
tabTextView.SetTextColor(textColor);

这篇关于有没有办法在不使用状态列表的情况下以编程方式设置特定的 Tablayout.Tab 文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-24 18:17:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068494.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   情况下   文本   颜色   状态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!