I have a fab button with camera icon (defined in xml) I want on click to rotate the icon and replace it by x...
I am using the following xml to make a rotation
Thank you
You can do that using ObjectAnimator, here:
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ObjectAnimator.ofFloat(fab, "rotation", 0f, 360f).setDuration(800).start();
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (isWhite){
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_add_black_48dp));
isWhite = false;
} else {
fab.setImageDrawable(getResources().getDrawable(R.drawable.ic_add_white_48dp));
isWhite = true;
}
}
}, 400);
}
});
Icon will change in the middle of rotation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With