How to make Floating Action Button background Gradient?

后端 未结 7 2014
长情又很酷
长情又很酷 2020-12-30 12:00

The code for FAB:



        
相关标签:
7条回答
  • 2020-12-30 12:40

    I tried a bunch of different answers but all had their shortcomings or didn't work with the material FAB. When I realized this is not what it is meant for I simply replaced it with an ImageView. This works great and looks identical.

    <ImageButton
        android:id="@+id/floatingActionButton"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:background="@drawable/fab_gradient"
        android:elevation="6dp"
        ... />
    

    fab_gradient.xml:

    <ripple android:color="?attr/colorControlHighlight"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <layer-list>
                <item>
                    <shape android:shape="oval">
                        <gradient
                            android:type="linear"
                            android:angle="90"
                            android:startColor="@color/startColor"
                            android:endColor="@color/endColor" />
                    </shape>
                </item>
                <item android:drawable="@drawable/vector_icon" android:gravity="center" />
            </layer-list>
        </item>
    </ripple>
    
    0 讨论(0)
提交回复
热议问题