我想去掉按钮的阴影,使它看起来更平坦。
我现在有这个:
但我想要的是:
我想去掉按钮的阴影,使它看起来更平坦。
我现在有这个:
但我想要的是:
当前回答
我使用自定义样式
<style name="MyButtonStyle" parent="@style/Widget.AppCompat.Button.Borderless"></style>
别忘了加上
<item name="android:textAllCaps">false</item>
否则按钮文本将是大写的。
其他回答
以上所有答案都很棒,但我将建议另一种选择:
<style name="FlatButtonStyle" parent="Base.Widget.AppCompat.Button">
<item name="android:stateListAnimator">@null</item>
<!-- more style custom here -->
</style>
科特林
stateListAnimator = null
Java
setStateListAnimator(null);
XML
android:stateListAnimator="@null"
带有自定义按钮;使用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)
它要求API级别为21
android:outlineProvider="none"
使用这个作为你的按钮的背景可能会有所帮助,根据你的需要改变颜色
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape android:shape="rectangle">
<solid android:color="@color/app_theme_light" />
<padding
android:left="8dp"
android:top="4dp"
android:right="8dp"
android:bottom="4dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/app_theme_dark" />
<padding
android:left="8dp"
android:top="4dp"
android:right="8dp"
android:bottom="4dp" />
</shape>
</item>
</selector>