2

I am using this library for floating action button

https://github.com/futuresimple/android-floating-action-button

If anyone is aware about it, we know that we can change the background color of floating action menu with this line in XML:

fab:fab_addButtonColorNormal="@color/floating_action_menu"

Is there a way to do so programmatically?

floating<enu.setBackgroundColor(color)

Doesn't work......

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Hirak Chhatbar
  • 3,159
  • 1
  • 27
  • 36
  • Possible duplicate of [How to change background color of floating action menu](http://stackoverflow.com/questions/30099725/how-to-change-background-color-of-floating-action-menu) – Baptiste Pernet Nov 24 '15 at 19:04

4 Answers4

2

Considering you might have found solution till now, but still adding an answer have a look...

floatingMenu.setBackgroundColor(getResources().getColor(R.color.yourColor));

this should work!

same way you can Change Normal,Pressed colour as well.

floatingMenu.setMenuButtonColorNormal(getResources().getColor(R.color.yournormalColor));
floatingMenu.setMenuButtonColorPressed(getResources().getColor(R.color.yourpressedColor));

this is the dependency for this compile 'com.github.clans:fab:1.6.2'

and github link

Shishram
  • 1,514
  • 11
  • 20
  • @Denis Yakovenko its tested code and working for me, if its wrong please elaborate what's wrong in this code. – Shishram Jan 19 '16 at 15:26
  • 1
    `floatingMenu.setBackgroundColor(..)` doesn't really set the background of the `FloationActionsMenu` element, it sets the background of the area the whole menu takes. And also `setMenuButtonColorNormal` and `setMenuButtonColorPressed` methods don't exist at all in the library the topic creator mentioned. Are you sure you tested the code using the mentioned library? If not, please provide the link for the library you used. – Denis Yakovenko Jan 19 '16 at 15:34
  • just edited answer, You can check now.@DenisYakovenko – Shishram Jan 19 '16 at 15:39
0

Recently I has the same problem including the fact that I wanted to add an icon also. So I came up with maybe not a correct solution but for me it seems to be working. Check this answer from this question How to set icon to getbase FloatingActionsMenu. I can not include the whole answer as it big. I hope this helps.

I have also found another library that seems to include everything that I need but I did not find the time yet to test it, but it looks promising (Clans/FloatingActionButton).

Thanos
  • 1,618
  • 4
  • 28
  • 49
0
app:fab_colorNormal="@color/app_yellow_color"
app:fab_colorPressed="@color/app_dark_grey_color"
Pawan Chaurasiya
  • 881
  • 2
  • 16
  • 30
-1

FloatingActionMenu is just a ViewGroup that suppose to hold children, presumably FloatingActionButtons. Attributes that have add as prefix in their names like fab:fab_addButtonColorNormal are doing the same as they would do to FloatinActionButton.

You can get reference to the initially added FloatingActionButton in the floating menu like:

FloatingActionButton initialFloating = (FloatingActionButton)mFloatingActionMenu.findViewById(R.id.fab_expand_menu_button)

And call

initialFloating.setColorNormal(normalColor) or initialFloating.setColorPressed(pressedColor)

If you want to apply the same color to all components of the floating menu, just iterate over children, cast them to FloatingActionButton and apply the color.

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148