📜  materialbutton 移除阴影 xml - Java (1)

📅  最后修改于: 2023-12-03 15:32:49.967000             🧑  作者: Mango

MaterialButton 移除阴影

MaterialButton是Android官方推出的一种控件,这个控件可以用来实现按钮的样式。然而,MaterialButton的默认样式带有阴影效果,如果您想要去除这个阴影,那么我们可以通过修改xml或Java代码来实现。

通过修改xml来移除阴影

我们可以在MaterialButton的布局文件中通过设置app:backgroundTint为我们想要的背景色来实现移除阴影。下面是一个示例:

<com.google.android.material.button.MaterialButton
    android:id="@+id/myButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="My Button"
    app:backgroundTint="@color/colorPrimary"/>

通过Java代码来移除阴影

如果您更喜欢通过Java代码的方式来移除阴影,那么可以在Java代码中调用MaterialButton的setSupportBackgroundTintList()方法来实现。下面是一个示例:

MaterialButton myButton = findViewById(R.id.myButton);
myButton.setSupportBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.colorPrimary)));

以上就是MaterialButton移除阴影的两种实现方式。您可以根据自己的需要选择更为方便的方式来实现。