Fab in Lollipop shows strange shadow on long press

自古美人都是妖i 提交于 2020-01-17 08:21:47

问题


I am using the FloatingActionButton in a CoordinatorLayout:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:tint="@color/white"
    app:fabSize="normal"
    app:layout_anchor="@+id/view_pager_imageformat_carousel"
    app:layout_anchorGravity="bottom|end"
    app:srcCompat="@drawable/ic_playlist_add_black_24dp"
    app:useCompatPadding="true" />

and it works fine with most Android Apis, but in Android 5 and 5.1 it shows a boxed shadow when it is pressed:

->

I tried setting clipChildren to false in the CoordinatorLayout, without any effect and looked through other available options wihtout success so far.

Has anyone encountered the same problem and came up with a solution?


回答1:


It turned out that the culprit was useCompatPadding.

Removing it solved the shadow problem.

To fix the margins I used this answer which basically uses custom margins with two different styles, default and ond for api 21+

But this is in fact an ugly solution and the margins are not perfect, so I am open to better solutions.




回答2:


You can add app:rippleColor="@color/transparent" to set the ripple color to transparent.




回答3:


Try to set elevation:

app:elevation="0dp"


来源:https://stackoverflow.com/questions/44199012/fab-in-lollipop-shows-strange-shadow-on-long-press

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