Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Floating Action Button Semi Transparent Background Color

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"/> 

enter image description here

And without any drawable.

enter image description here

like image 715
Mbt925 Avatar asked May 28 '16 12:05

Mbt925


People also ask

How do you change the background color of a floating action button?

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.

How do I remove the floating action button background color in Android?

Setting the android:outlineProvider to none and the app:backgroundTint to null can help achieve this.

What are floating action buttons?

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.


Video Answer


2 Answers

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.

like image 128
WaBayang Avatar answered Sep 23 '22 03:09

WaBayang


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"/> 
like image 34
Rustam Samandarov Avatar answered Sep 20 '22 03:09

Rustam Samandarov