Google has shown some nice ways that buttons are shown on Lollipop here.
I\'m talking about both the raised and the flat buttons.
How can I mimic them on pre
This one is hacky according to Yigit (google dev on cardview) but does a descent job.
You can use negative numbers in order to get rid of the padding and margin inside of CardView.
Tested on api 15 nexus one and nexus 4 emulators. This solution will work on pre lollipop.
Code:
final CardView cardView = (CardView) rootView.findViewById(R.id.elevated_button_card);
final Button button = (Button) rootView.findViewById(R.id.elevated_button);
button.setOnTouchListener(new View.OnTouchListener() {
ObjectAnimator o1 = ObjectAnimator.ofFloat(cardView, "cardElevation", 2, 8)
.setDuration
(80);
ObjectAnimator o2 = ObjectAnimator.ofFloat(cardView, "cardElevation", 8, 2)
.setDuration
(80);
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
o1.start();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
o2.start();
break;
}
return false;
}
});