android - 如何为 setCompoundDrawablesWithIntrinsicBounds 设置色调颜色?

标签 android image android-vectordrawable tint

我有一个选项卡布局,我在其中设置文本和矢量图像,如下所示:

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

如何更改可绘制矢量图像的色调?

最佳答案

像这样尝试:

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

关于android - 如何为 setCompoundDrawablesWithIntrinsicBounds 设置色调颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43087035/

相关文章:

android - 在 Android 上将 mask 应用于视频预览

android - 当屏幕关闭(背景)时,是否可以在 Android 设备之间共享 "data"?

java - 使用 Android 简单文件选择器时出现问题

javascript - 在javascript中定向后 Canvas 将图像裁剪为正方形

android - 创建带有阴影的矢量可绘制对象以覆盖图像

Android 删除折线或替换

php - 如何避免滥用图像预览流量?

css - 我应该将 OctoberCMS 的图像文件放在哪里

android - 如何为android中的自适应图标格式化/调整VectorDrawable的大小

android - ImageButton 上的 VectorDrawable 很难看