问题
I'm trying to replace the third party FloatingActionButton with the native one which is packaged in library com.android.support:design:22.2.0
.The default look has a dark shadow around the image,How can I get rid of it? I know the former one provides with the method setShadow()
,but I just can't find similar one from the latter.

This is the related XML layout:
<android.support.design.widget.FloatingActionButton
android:id="@+id/alarm_front"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_icon_alarm_notset" />
And I have set its background color to yellow.
mAlarmBtn.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.floatButtonColor)));
回答1:
Override the default elevation of the FAB by adding:
android:elevation="0dp"
Or in code call View.setElevation(float)
回答2:
Override the default elevation of the FAB by adding the following:
app:elevation="0dp"
回答3:
Add this
android:elevation="0dp"
app:elevation="0dp"
It's will be like :
<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
android:elevation="0dp"
app:elevation="0dp"
app:fabSize="normal"
android:scaleType="fitCenter"/>
回答4:
If you are using the support libraries - the latest Android Studio templates us them. Check the imports
import android.support.design.widget.FloatingActionButton;
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
//if using support app compat
fab.setCompatElevation(16.0f);
else if youre only supporting newer sdk versions
fab.setElevation();
//call requires SDK 21
see
.../app/build.gradle
minSdkVersion 18 << less than 21 so req support libraries
targetSdkVersion 25
回答5:
Tried all suggestions above and nothing has worked for API 23 and high. I've ended up with this, which has completely removed the shadow:
app:backgroundTint="@android:color/transparent"
app:borderWidth="0dp"
Below is how my button looks like now:
Before the change it looked as follows:
回答6:
Make borderWidth to 0
app:borderWidth="0dp"
来源:https://stackoverflow.com/questions/30613921/how-to-remove-floatingactionbuttons-surrounding-shadow