本文介绍了有没有办法在不使用状态列表的情况下以编程方式设置特定的 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:关键词]
发布评论