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

我现在有这个:

但我想要的是:


当前回答

另一种选择是添加

style="?android:attr/borderlessButtonStyle"

到您的按钮xml,如这里所述 http://developer.android.com/guide/topics/ui/controls/button.html

一个例子是

<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
style="?android:attr/borderlessButtonStyle" />

其他回答

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

更新材料组件

如果你之前使用过这样的东西:

<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:buttonStyle">@style/NoShadowButton</item>
</style>

<style name="NoShadowButton" parent="Widget.AppCompat.Button">
    <item name="android:stateListAnimator">@null</item>
</style>

和我一样,你也在挠头,想知道为什么你已经迁移到了Theme.MaterialComponents.Light。*,这是因为buttonStyle只引用AppCompat按钮样式-有一个新的样式materialButtonStyle。这解决了我的问题:

<style name="MyTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="materialButtonStyle">@style/Widget.MaterialComponents.Button.UnelevatedButton</item>
</style>

这里有一个很好的指南,告诉您还有哪些已经更改,以及如何正确迁移。

带有自定义按钮;使用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)

try: android:stateListAnimator="@null"

另一种选择是添加

style="?android:attr/borderlessButtonStyle"

到您的按钮xml,如这里所述 http://developer.android.com/guide/topics/ui/controls/button.html

一个例子是

<Button
android:id="@+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage"
style="?android:attr/borderlessButtonStyle" />