如何自定义FAB涟漪效果Android

时间:2019-06-13 17:22:47

标签: android xml android-layout rippledrawable

我想为FloatingActionButton自定义android涟漪效果,因此当我单击按钮时,图标更改为一些文本,动画更改为如下内容:

enter image description here

这是我的xml代码:

with cte as (select Name, Employee_ID, Order_Number, City,
dense_rank() over (partition by Employee_ID order by Order_Number) as rank,
lag(City) over (partition by Employee_ID order by Order_Number) as previousCity
from #Employee)
select 
    Name, Employee_ID, Order_Number, City,
    case when previousCity = city then rank - 1
         else rank end as rank
from cte

color / fab_icon.xml

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:fabCustomSize="180dp"
        app:srcCompat="@color/fab_icon"
        app:borderWidth="1dp"
       android:outlineAmbientShadowColor="@android:color/transparent"
        android:outlineSpotShadowColor="@android:color/transparent"
        android:clickable="true"
        android:tint="@color/fab_tint"
        android:elevation="6dp"
        app:rippleColor="@color/ripple_color"
        app:maxImageSize="90dp"
        android:backgroundTint="@color/black_theme2"
        app:backgroundTint="@color/ripple_color"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp"
        app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="8dp"
        app:layout_constraintHorizontal_bias="0.5"
        android:id="@+id/new_trip"
        app:layout_constraintBottom_toTopOf="@+id/watching_trips"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toTopOf="parent"/>                     

color / fab_tint.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false" android:drawable="@drawable/ic_add" android:color="@android:color/transparent"></item>
    <item android:state_pressed="true" android:drawable="@drawable/ic_update" android:color="@color/yellow_theme2"></item>
    <item android:state_hovered="false" android:drawable="@drawable/ic_add" android:color="@android:color/transparent"></item>
    <item android:state_hovered="true" android:drawable="@drawable/ic_update" android:color="@android:color/transparent"></item>
</selector>

0 个答案:

没有答案