-2

I am novice for the android world. Just for improving my skills, I am learning android. So I am creating a social app there I have used floating action button, on which if user clicks it increases the number of likes.

By default, floating button is taking accent color but I want to use different color. I tried a lot but not getting any solution. Yes, there are so many libraries available that I can use to achieve my goal, but I do not want to use any external library. I believe to use core methods of android.

Is it like, there is no solution except using external libraries? I tried this one, but xml file is throwing error when I am using app tag.

If you wish to change the color

    in XML with attribute app:backgroundTint
    in code with .setBackgroundTintList

I am using this library:

com.android.support:design:23.1.1

Please comment on the same. I know for Android guru's this is not big deal. I know this question has been already but I didn't get solution for my problem. That's why I am opening this question again.

Prabhakar
  • 237
  • 1
  • 3
  • 10

1 Answers1

0

As described in the documentation, by default it takes the color set in styles.xml attribute colorAccent.

The background color of this view defaults to the your theme's colorAccent. If you wish to change this at runtime then you can do so via setBackgroundTintList(ColorStateList).

If you wish to change the color

In XML with attribute app:backgroundTint

<android.support.design.widget.FloatingActionButton
    xmlns:app="http://schemas.android.com/apk/res-auto"
    ...
    app:backgroundTint="@color/orange"
    app:borderWidth="0dp"
    app:elevation="6dp"
    app:fabSize="normal" />

in code use setBackgroundTintList

Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
Silvans Solanki
  • 1,267
  • 1
  • 14
  • 27