I want to use FAB with semi transparent background color. But I am getting a FAB with two different colors. What's the problem?
<android.support.design.widget.FloatingActionButton xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|left" android:fadingEdgeLength="5dp" app:borderWidth="0dp" app:elevation="4dp" app:backgroundTint="#99f03456" app:fabSize="normal"/>
And without any drawable.
To change background color of Floating Action Button in Kotlin Android, set the backgroundTint attribute (in layout file) or backgroundTintList property (in Kotlin file) of FAB with the required color.
Setting the android:outlineProvider to none and the app:backgroundTint to null can help achieve this.
A floating action button (FAB) is a circular button that triggers the primary action in your app's UI. This page shows you how to add the FAB to your layout, customize some of its appearance, and respond to button taps.
Got the same issue here. I tried to set alpha transparency in xml using backgroundTint but it didn't work and resulted in the same appearance as in your screenshots (two circles).
So I set it in code like this :
floatingButton = (FloatingActionButton) findViewById(R.id.fab); floatingButton.setAlpha(0.25f);
And the look is now consistent.
Set elevation and pressedTranslationZ zero to remove the effects
<android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClickMyLocation" app:backgroundTint="@color/transparentColor" app:srcCompat="@drawable/ic_my_location" app:elevation="0dp" app:pressedTranslationZ="0dp"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With