medyo / Fancybuttons

Icons, Borders, Radius ... for Android buttons
1.77k stars 397 forks source link

When set radius programmatically, ripple effect gone? #127

Open traitaodoc1994 opened 5 years ago

traitaodoc1994 commented 5 years ago

I was created a class extends class FancyButton like this : `public class BorderButton extends FancyButton {

public BorderButton(Context context) {
    super(context);
    changeThemeButton("#29a19c","#29a19c");
}

public BorderButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    changeThemeButton("#29a19c","#29a19c");

}

private void changeThemeButton(String textColor, String borderColor){
    int txtColor = Color.parseColor(textColor);
    int borColor = Color.parseColor(borderColor);
    setBorderWidth(2);
    setBorderColor(borColor);
    setTextColor(txtColor);
    setFocusBackgroundColor(borColor);
    // setRadius not work here because getHeight = 0
    //        setRadius(getHeight()/2);
    setBackgroundColor(ContextCompat.getColor(getContext(),android.R.color.transparent));
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // setRadius worked but ripple effect gone
    setRadius(getHeight()/2);
}

}` How can I set radius programmatically and keep ripple effect work ?