我想去掉按钮的阴影,使它看起来更平坦。

我现在有这个:

但我想要的是:


当前回答

材质设计按钮添加到按钮xml: 风格= " @style / Widget.MaterialComponents.Button.UnelevatedButton”

其他回答

@Alt-Cat的答案对我有用!

r.t r. borderlessbuttonstyle不包含阴影。

按钮的文档很棒。

同样,你也可以在你的自定义按钮中,在第二个构造函数中设置这个样式。

    public CustomButton(Context context, AttributeSet attrs) {
        this(context, attrs, R.attr.borderlessButtonStyle);
    }

科特林

stateListAnimator = null

Java

setStateListAnimator(null);

XML

android:stateListAnimator="@null"

一个更简单的方法是添加这个标签到你的按钮:

android:stateListAnimator="@null"

尽管它需要API级别21或更高。

带有自定义按钮;使用R.style。Widget_AppCompat_Button_Borderless, Kotlin way-

class CSButton @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = R.style.Widget_AppCompat_Button_Borderless
) : AppCompatButton(context, attrs, defStyleAttr)

材质设计按钮添加到按钮xml: 风格= " @style / Widget.MaterialComponents.Button.UnelevatedButton”