I created a button in Android like this,
Button btn = new Button(getContext());
Initially, the button will be animated when I click on it. It becomes darker when I press on it, and it resumes to its original color when I release the button.
However, if I change the background color, such as btn.setBackgroundColor(Color.RED)
, the click animation will no longer there, and this really annoyed me.
What I want is simple, I just want to keep the click animation even I changed the button background color.
Updates:
Finally, I chose the library Material for my project in case anyone want to know.
There are several Material UI libraries on Github that backward support SDK version <21, however, it seemed that each of them has its own problems and bugs. Most of them support constructions of UI components using XML quite well, but they do not support construction in Java very well. For example, it seemed that the library I am using cannot construct Material style EditText
programmatically in Java.
I tried RippleEffect, material-ripple and Material, and Material worked better in my case.