设置颜色标签主机指示灯指示灯、颜色、主机、标签

2023-09-06 07:33:16 作者:挑灯看剑↗

你如何设置选项卡主机指示剂颜色的颜色我想改变淡蓝色默认颜色让说红色。

How do you set the color of the tab host indicator color I want to change the light blue default color to lets says RED.

和我需要这种编程方式,因为我编程制作的标签。

And I need to this programatically as I am making the tabs programatically.

我做了一些研究,看了看这个例子,但它不为我工作。随着progamtic方法。

I did some research and looked at this example but it does not work for me. With the progamtic approach.

TabWidget当前选项卡的底线颜色

感谢

推荐答案

您可以通过编程方式做到这一点,甚至改变颜色,只要你想,通过遵循的链接的问题你提到,再加上加入的 Col​​orFilter 来调整颜色。

You can do this programmatically, even change the color as you want, by following the solution in the linked question you mention, plus adding a ColorFilter to adjust the color.

所以:

创建相应的绘制。最简单的方法,如在答案之一提到的,使用 https://jgilfelt.github.io/ Android的actionbarstylegenerator / 将到项目的 tab_indicator_ab_example.xml (以绘)加上6相关PNG文件(制表_ *。PNG)每次绘制密度。创建选项卡后,使用code,它在 TabWidget 子视图迭代来设置他们的背景,但是: 而不是设置绘制原样,的使用滤色镜,以改变其颜色为所需的单的的。 Create the appropriate drawable. The easiest way, as mentioned in one of the answers, is using https://jgilfelt.github.io/android-actionbarstylegenerator/ Place into your project the tab_indicator_ab_example.xml (in drawable) plus the 6 associated png files (tab_*.png) for each drawable density. After creating the tabs, use the code that iterates over the TabWidget child views to set their background, however: Instead of setting the drawable as-is, use a color filter to change its color to the desired one.

相反这code的:

for(int i = 0; i < widget.getChildCount(); i++) {
    ... /* same as before */

    v.setBackgroundResource(R.drawable.your_tab_selector_drawable);
}

这样写:

for(int i = 0; i < widget.getChildCount(); i++) {
    ... /* same as before */

    Drawable d = getResources().getDrawable(R.drawable.tab_indicator_ab_example);
    d.setColorFilter(Color.GREEN, PorterDuff.Mode.SRC_IN);
    v.setBackgroundDrawable(d);
}