我想去掉按钮的阴影,使它看起来更平坦。
我现在有这个:
但我想要的是:
我想去掉按钮的阴影,使它看起来更平坦。
我现在有这个:
但我想要的是:
当前回答
以上所有答案都很棒,但我将建议另一种选择:
<style name="FlatButtonStyle" parent="Base.Widget.AppCompat.Button">
<item name="android:stateListAnimator">@null</item>
<!-- more style custom here -->
</style>
其他回答
我使用自定义样式
<style name="MyButtonStyle" parent="@style/Widget.AppCompat.Button.Borderless"></style>
别忘了加上
<item name="android:textAllCaps">false</item>
否则按钮文本将是大写的。
另一种选择是添加
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" />
您可以使用TextView代替按钮,并在java代码中添加单击侦听器。
I.e.
在活动布局xml中:
<TextView
android:id="@+id/btn_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:text="@string/btn_text"
android:gravity="center"
android:textColor="@color/colorAccent"
android:fontFamily="sans-serif-medium"
android:textAllCaps="true" />
在activity Java文件中:
TextView btnTextView = (TextView) findViewById(R.id.btn_text_view);
btnTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// handler code
}
});
简单的
android:elevation="0dp"
它要求API级别为21
android:outlineProvider="none"