How to Change image color dynamically in android?

前端 未结 6 828
死守一世寂寞
死守一世寂寞 2020-12-13 12:58

I am doing such type of project ,In my project change Image color dynamically.

I have a one black shape color image ,when user click on this ima

6条回答
  •  悲哀的现实
    2020-12-13 13:39

    Here's how I do this: It's pulling the color from a resource xml file.

    
    #FFAAAAAA
    
    

    In your activity .java file:

    import android.graphics.PorterDuff.Mode;
    
    Resources res = context.getResources();
    final ImageView image = (ImageView) findViewById(R.id.imageId);
    final int newColor = res.getColor(R.color.new_color);
    image.setColorFilter(newColor, Mode.SRC_ATOP);
    

    To clear it call:

    image.setColorFilter(null);
    

提交回复
热议问题