Created
August 2, 2017 14:48
-
-
Save watabee/a505c9dbd946a97dd8a5e87672547674 to your computer and use it in GitHub Desktop.
An ImageView which can highlight.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.ColorFilter; | |
import android.graphics.PorterDuff; | |
import android.graphics.PorterDuffColorFilter; | |
import android.support.v7.widget.AppCompatImageView; | |
import android.util.AttributeSet; | |
public class HighlightableImageView extends AppCompatImageView { | |
private static final ColorFilter COLOR_FILTER = new PorterDuffColorFilter(0x40000000, PorterDuff.Mode.SRC_ATOP); | |
public HighlightableImageView(final Context context) { | |
this(context, null); | |
} | |
public HighlightableImageView(final Context context, final AttributeSet attrs) { | |
this(context, attrs, 0); | |
} | |
public HighlightableImageView(final Context context, final AttributeSet attrs, | |
final int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
setClickable(true); | |
} | |
@Override | |
public void setPressed(final boolean pressed) { | |
super.setPressed(pressed); | |
if (pressed) { | |
setColorFilter(COLOR_FILTER); | |
} else { | |
clearColorFilter(); | |
} | |
invalidate(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment