I observe this weird behavior, please help me figure it out!
I simply set a onTouchListner to a button. For the onTouch()
callback, if I set it return false, when I click on the button, I can see the click animation effect of the button (simply color change); However, if I set it return true, when I click on the button, the click animation effect just disappeared.
Below is the code
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = findViewById(R.id.btn);
btn.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.setClickable(true);
Log.d("myTrack", "onTouch");
return true; // I cannot see the animation effect when click
return false; // I can see the animation effect when click
}
});
}
}