Reaz Murshed Reaz Murshed - 5 months ago 81
Android Question

FloatingActionButton is not changing colour

I'm using this library which is pretty awesome for implementing floating action button with customized menu and many other stuffs.

But while using this library I'm facing trouble with changing the color of the

FloatingActionButton
inside a
FloatingActionMenu
. I tried putting
fab:manu_colorNormal
as a property of the
FloatingActionButton
, but it seems it has no effect and showing the default colour.

Here's the layout I'm using. Note that, I've used
xmlns:fab="http://schemas.android.com/apk/res-auto"
. It was suggested somewhere to check if the
xmlns:fab
is pointed to
apk/res-auto
. I set that properly, but yet no luck.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background">

<com.github.clans.fab.FloatingActionMenu
android:id="@+id/fab_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
fab:menu_colorNormal="@color/fab_close_background"
fab:menu_colorPressed="@color/fab_close_background_pressed"
fab:menu_colorRipple="@color/fab_close_background_ripple">

<com.github.clans.fab.FloatingActionButton
android:id="@+id/menu_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_white_24dp"
fab:fab_size="mini"
fab:menu_colorNormal="@color/fab_delete_background"
fab:menu_colorPressed="@color/fab_delete_background_pressed"
fab:menu_colorRipple="@color/fab_delete_background_ripple" />

</com.github.clans.fab.FloatingActionMenu>

</RelativeLayout>


Note: I could change the colour of the
FloatingActionMenu
button successfully.
menu_colorNormal
works perfectly for the close button in my layout.

Here's how it looks like in my application. Red is the default colour which I'm trying to change. The issue is reported here in Github.

Floating action menu along with mini buttons

Answer

Replace fab:menu_colorNormal to fab:fab_colorNormal in FloatingActionButton

fab:menu_colorNormal is used to set the color of menu icon and fab:fab_colorNormal is used to set the color of floating action button.

See the doc here.

Use following code:

 <com.github.clans.fab.FloatingActionMenu
        android:id="@+id/menu_green"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginRight="150dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        fab:menu_icon="@drawable/ic_star"
        fab:menu_animationDelayPerItem="0"
        fab:menu_colorNormal="#43A047"
        fab:menu_colorPressed="#2E7D32"
        fab:menu_colorRipple="#1B5E20"
        fab:menu_labels_maxLines="2"
        fab:menu_labels_ellipsize="end">

        <com.github.clans.fab.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_edit"
            fab:fab_label="Menu item 1"
            fab:fab_colorNormal="#43A047"
            fab:fab_colorPressed="#2E7D32"
            fab:fab_colorRipple="#1B5E20" />

    </com.github.clans.fab.FloatingActionMenu>
Comments