I want to highlight a button when pressed and release without using any images,so i am using the below code from one the post on SO but its not working for me:
public class MainActivity extends Activity {
ImageButton myButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myButton = (ImageButton) findViewById(R.id.button);
myButton.setOnTouchListener(new ButtonHighlighterOnTouchListener(myButton));
}
public class ButtonHighlighterOnTouchListener implements OnTouchListener {
final ImageButton imageButton;
public ButtonHighlighterOnTouchListener(final ImageButton imageButton) {
super();
this.imageButton = imageButton;
}
@Override
public boolean onTouch(final View view, final MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
//grey color filter, you can change the color as you like
imageButton.setColorFilter(Color.parseColor("#5F2444"));
System.out.println("called down");
} else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
imageButton.setColorFilter(Color.parseColor("#245F30"));
System.out.println("called up");
}
return false;
}
}
What is the problem here?
Original post is here : How to make Button highlight?