Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)

Been trying for hours to change Material's Floating Action Button color, but without success.

<android.support.design.widget.FloatingActionButton

    android:id="@+id/profile_edit_fab"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_gravity="end|bottom"

    android:layout_margin="16dp"

    android:clickable="true"

    android:src="@drawable/ic_mode_edit_white_24dp" />

I have tried to add

android:background="@color/mycolor"

or via code

FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.profile_edit_fab);

fab.setBackgroundColor(Color.parseColor("#mycolor"));

or

fab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#mycolor")));

None of the above worked for me.

2 Answers

0 votes
by (46k points)

You can check out this new method that has been added with Java 8 to do just what you asked for.

import static java.lang.Math.toIntExact;

long foo = 10L;

int bar = toIntExact(foo);

Will return an ArithmeticException in the event of an overflow.

check out: Math.toIntExact(long)

Some other overflow safe methods have been attached to Java 8. They end with exact.

Examples:

Math.incrementExact(long)

Math.subtractExact(long, long)

Math.decrementExact(long)

Math.negateExact(long),

Math.subtractExact(int, int)

0 votes
by (140 points)
Well...give it a try.

search for srcCompat in the attributes taband change the color. It worked for me.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Apr 6, 2021 in Java by Jake (7k points)
0 votes
1 answer

Browse Categories

...