MaterialDesignLibrary icon indicating copy to clipboard operation
MaterialDesignLibrary copied to clipboard

Change BackGroundColor of ButtonFlat

Open patelakshay13890 opened this issue 10 years ago • 6 comments

On Changing ButtonFlat's BackGroundColor from XML as well as from Code only Text's Font Color get changed instead of ButtonFlat's BackGroundColor.. So how do i can achieve this in ButtonFlat ? Expeting +ve & quick response..!!!

patelakshay13890 avatar Feb 18 '15 11:02 patelakshay13890

It seems that every background color you enter is overwritten in this line.

public ButtonFloat(Context context, AttributeSet attrs) { super(context, attrs); X-----> setBackgroundResource(R.drawable.background_button_float);

:(

Drakot avatar Feb 20 '15 14:02 Drakot

Actually when defining the background property sets the rippleColor property. And when the rippleColor property is defined then the background property has no effect.

filipebezerra avatar Feb 21 '15 02:02 filipebezerra

I noticed this behavior for the ButtonFloat too. It seems that setAttributes gets not called in the Constructor of ButtonFloat. Right now i get around by subclassing it and calling it in the Constructor. Maybe this helps here too.

public class MyButtonFloat extends ButtonFloat
{
    public MyButtonFloat(final Context context, final AttributeSet attrs)
    {
        super(context, attrs);

        setAttributes(attrs);
    }
}

Edit: as @dilizarov pointed out i missed something (Thank you) : Now in your xml Layout change

com.gc.materialdesign.views.ButtonFloat

to

com.path.to.your.MyButtonFloat

ChristopherGittner avatar Feb 22 '15 12:02 ChristopherGittner

@Gittner Thank you so much. That is awesome!

To anyone new to customizing these types of things, once you make Gittner's fix, head to your XML layout files and wherever you originally used the com.gc.materialdesign.views.ButtonFloat, just swap it out with com.path.to.your.MyButtonFloat. :)

dilizarov avatar Feb 23 '15 00:02 dilizarov

@dilizarov you can also change color programmatically using setBackgroundColor

emaleavil avatar Apr 06 '15 15:04 emaleavil

ButtonFlat is always transparent! if you want to use a rectangle button with background color you can use ButtonRectangle that is quite the same button but with coloured background

xcelder avatar Nov 16 '16 22:11 xcelder