-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting animation in a FAB lib. #23
Comments
have you used co-ordinate layout |
I had the same need and I figured it out. FloatingActionButton fab_add = (FloatingActionButton) findViewById(R.id.fab_add);
final Animatable icon = (Animatable) ResourcesCompat.getDrawable(this, R.drawable.ic_arrow_to_drawer);
fab_add.setImageDrawable((Drawable)icon);
fab_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
icon.start();
}
}); It is pretty much the same case with any other view that supports drawable as icon or background. |
@PureDark, this works, but only once for each drawable. How do you reset the animation state, so you can run the animation over and over? |
@svenoaks private Animatable icon; and do as below every single time: fab.setImageDrawable((Drawable)icon);
icon.start(); a more elegance way would be: public class MyFloatingActionButton extends FloatingActionButton {
private Animatable startIcon, endIcon;
public MyFloatingActionButton(Context context) {
super(context);
}
public MyFloatingActionButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyFloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void setStartIcon(Animatable startIcon){
this.startIcon = startIcon;
this.setImageDrawable((Drawable)startIcon);
}
public void setEndIcon(Animatable endIcon){
this.endIcon = endIcon;
}
public void start(){
if(startIcon!=null){
this.setImageDrawable((Drawable)startIcon);
startIcon.start();
}
}
public void reverse(){
if(endIcon!=null){
this.setImageDrawable((Drawable)endIcon);
endIcon.start();
}
}
} And set the initial icon in onCreate Animatable crossStartIcon = (Animatable) ResourcesCompat.getDrawable(this, R.drawable.vector_animated_cross_0_to_45);
Animatable crossEndIcon = (Animatable) ResourcesCompat.getDrawable(this, R.drawable.vector_animated_cross_45_to_0);
fabAdd = (MyFloatingActionButton) findViewById(R.id.fab_add);
fabAdd.setStartIcon(crossStartIcon);
fabAdd.setEndIcon(crossEndIcon); |
Thanks but gets messed up in random ways when screen rotates and variables reassigned. Only consistent way was to use |
Hello! Congratulations at first.
I want this amazing animation on the button of my radio player, but im already using a FAB lib (https://github.com/Clans/FloatingActionButton) and I was not able to understand how to put this effect on my button.
Any help is appreciated. Thanks in advance.
The text was updated successfully, but these errors were encountered: