设置颜色标签主机指示灯 [英] Set color tab host indicator

查看:196
本文介绍了设置颜色标签主机指示灯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

所以:


  1. 创建相应的绘制。最简单的方法,如在答案之一提到的,使用 https://jgilfelt.github.io/ Android的actionbarstylegenerator /

  2. 将到项目的 tab_indicator_ab_example.xml (以绘)加上6相关PNG文件(制表_ *。PNG)每次绘制密度。

  3. 创建选项卡后,使用code,它在 TabWidget 子视图迭代来设置他们的背景,但是:

  4. 而不是设置绘制原样,的使用滤色镜,以改变其颜色为所需的单的的。

  1. Create the appropriate drawable. The easiest way, as mentioned in one of the answers, is using https://jgilfelt.github.io/android-actionbarstylegenerator/
  2. Place into your project the tab_indicator_ab_example.xml (in drawable) plus the 6 associated png files (tab_*.png) for each drawable density.
  3. After creating the tabs, use the code that iterates over the TabWidget child views to set their background, however:
  4. 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);
}

这篇关于设置颜色标签主机指示灯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆