How to remove FloatingActionButton's surrounding shadow?

房东的猫 提交于 2019-12-18 14:02:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!