When I click on an Android Button, it ripples nicely. I want to trigger the same effect, but programmatically.
Right now, I use performClick()
and that works --- a click is registered and the button's onClick() code is called. However, there's no ripple/UI change. How can I make it so the ripple occurs when a perform a click programmatically?
Layout:
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Button" />
Code:
findViewById(R.id.myButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("DEBUG", "Saw Click");
}
});
findViewById(R.id.myButton).performClick();
Log.e("DEBUG", "Attempted click");