I need to change the background color of my FloatingActionButton
when clicked during runtime.
My code:
public static void setButtonTint(FloatingActionButton button, ColorStateList tint) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
((TintableBackgroundView) button).setSupportBackgroundTintList(tint);
} else {
ViewCompat.setBackgroundTintList(button, tint);
}
}
public void switchFABmode(){
switch (floatingActionButtonMode){
case 0:
setButtonTint(shareFAB,getResources().getColorStateList(R.color.colorGrey));
setButtonTint(deleteFAB,getResources().getColorStateList(R.color.colorPrimary));
floatingActionButtonMode = 1;
Toast.makeText(this, "Tap time to delete",Toast.LENGTH_SHORT).show();
break;
case 1:
shareFAB.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimary));
deleteFAB.setBackgroundColor(ContextCompat.getColor(this, R.color.colorGrey));
Toast.makeText(this,"Tap time to share", Toast.LENGTH_SHORT).show();
floatingActionButtonMode = 0;
break;
}
}
Does not accomplish that. Can someone point out my mistake, or provide me with a solution?