[英]Change the color of the icon in the ImageView in the java class
我通过 ImageView 显示了程序中的图标。 按下按钮时,黄色图标应变为红色。 我尝试了所有方法,但都没有奏效。 ...背景色... 他将 ImageView 变成了全方形的红色。 我只是想让图标改变颜色。 这很困难,请帮忙。 谢谢你。
我的代码:
ImageView Test = (ImageView) findViewById(R.id.TestImageIcon);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Here
Test.setcolor(R.id.red);
}
});
可以使用setColorFilter (color) 来完成。
尝试使用Test.setColorFilter(ContextCompat.getColor(YourActivity.this, R.color.red));
以编程方式更改图标的颜色Test.setColorFilter(ContextCompat.getColor(YourActivity.this, R.color.red));
你像这样改变drawable的色调:
imageView.setColorFilter(context.getResources().getColor(R.color.yourColor), PorterDuff.Mode.SRC_IN);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.