首页 > 解决方案 > 阴影问题 Floating Action Button (api = 19)

问题描述

我在 API <= 19 上遇到了 FAB 阴影问题。我使用了 compatElevation= 0f 并且阴影消失了。但它在 onClick 期间再次出现并且看起来很奇怪:

在此处输入图像描述

XML 代码:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/RateBtn"
    android:layout_width="@dimen/backet_Btn_size"
    android:layout_height="@dimen/backet_Btn_size"
    android:elevation="0dp"
    app:elevation="0dp"

    android:clickable="true"
    android:focusable="true"


    android:src="@drawable/star_rate2"
    app:backgroundTint="@color/w"


    app:layout_constraintEnd_toEndOf="@+id/langBtn2"
    app:layout_constraintStart_toStartOf="@+id/langBtn2"
    app:layout_constraintTop_toTopOf="@+id/SettingsBtn"

    app:rippleColor="@color/grey_700" />

代码:

var fb = view?.findViewById(R.id.RateBtn) as FloatingActionButton
val lp =it.layoutParams

            if (lp !=null){
                lp.width= size_fb
                lp.height=size_fb
                it.customSize=size_fb
                it.layoutParams= lp
            }

我认为当我尝试以编程方式更改 FAB 大小时存在一些问题。当我在 xml 中设置大小时,一切正常

标签: androidandroid-4.4-kitkatfloating-action-button

解决方案


爪哇

setStateListAnimator(null);

XML

android:stateListAnimator="@null"

推荐阅读