如何去除按钮阴影(安卓)

230

我想要去掉按钮上的阴影,使其看起来更加扁平。

现在的样式如下图所示:

带有阴影的取消按钮

但我想要的效果是这样的:

没有阴影的取消按钮


我在这里写评论,对我有用。https://dev59.com/914c5IYBdhLWcg3weqW9#30856094 - msamardzic
https://dev59.com/-oXca4cB1Zd3GeqPPvFG - smileVann
16个回答

485

另一种选择是添加

style="?android:attr/borderlessButtonStyle"

按照这里文档所述,将其添加到您的按钮XML中。

例如:

<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" />

1
这将移除按钮的样式,例如阴影和浮雕。添加带形状的选择器是可选的。这是一个更准确的答案。 - Juan José Melero Gómez
49
此外,我使用自定义样式来设计我的按钮。您可以通过以下方式扩展您的自定义样式: