如何为setCompoundDrawablesWithIntrinsicBounds设置颜色?

4

我有一个选项卡布局,在这个布局中,我设置文本和向量图像的方法如下:

    TextView tab2 = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
    tab2.setText("OFFER");
    tab2.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_offer, 0, 0);
    tabLayout.addTab(tabLayout.newTab().setCustomView(tab2));

我该如何更改可绘制矢量图像的色调颜色?
1个回答

4
尝试以下方法:

像这样:

Drawable drawables[] = textView.getCompoundDrawables();
drawables[0].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接