0 votes
1 view
in Java by (4.1k 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.

1 Answer

0 votes
by (46.1k 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)

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 25, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...