'How to change the shadow color of Button and CardView before API28
When I press a button, there is already a grey shadow provided by default style. I know it is from android:stateListAnimator. I want to change the shadow' s color. Can I do this in an animator xml?
I can use android:outlineSpotShadowColor to change the shadow color of Button and CardView, but it needs API 28.
My theme: from Theme.AppCompat.Light.NoActionBar
My CardView style: from Base.CardView
My CardView: <androidx.cardview.widget.CardView></>
My button style: from Widget.AppCompat.Button
My button: <Button/> or <androidx.appcompat.widget.AppCompatButton/>
I do not want to change to <com.google.android.material.button.MaterialButton/> or draw shadow by creating a button custom view.
Please help me.
button_state_list_anim_material.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="@integer/button_pressed_animation_duration"
android:valueTo="@dimen/button_pressed_z_material"
android:valueType="floatType"/>
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="@dimen/button_elevation_material"
android:valueType="floatType"/>
</set>
</item>
<!-- base state -->
<item android:state_enabled="true">
...
</item>
<item>
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="0"
android:valueTo="0"
android:valueType="floatType"/>
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="0"
android:valueType="floatType"/>
</set>
</item>
</selector>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
