bhaskar
bhaskar

Reputation: 1080

How to set tint color for setCompoundDrawablesWithIntrinsicBounds?

I have a tab layout in which i am setting the text and vector image like this:

    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));

How can i change the tint color for the drawable vector image?

Upvotes: 4

Views: 1572

Answers (1)

Yuriy Shemetov
Yuriy Shemetov

Reputation: 41

Try like this:

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

Upvotes: 4

Related Questions