in Android, I want to do something like this (but with 2 alternating colors black and white:
changing color with ripple effect like this
What I tried to do is :
1) set default backgroundTint & ripple color via XML
app:backgroundTint="@android:color/black"
app:rippleColor="@android:color/white"
2) in onclick method, changed backgroundTint to white and ripple color to black
set a string for initial color i.e. high_color = "black"
. then,
fab.setOnClickListener(new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View v) {
if(high_color.equals("black")){
fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.white)));
fab.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.black)));
fab.setRippleColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
high_color = "white";
}else {
fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.black)));
fab.setImageTintList(ColorStateList.valueOf(ContextCompat.getColor(getApplicationContext(), R.color.white)));
fab.setRippleColor(ContextCompat.getColor(getApplicationContext(), R.color.whites));
high_color = "black";
}
}
});
now I am getting something like this :
what I am getting is this
is there anyway to make this one look like the first one ? like slowing down the ripple animation speed or anything like that?