How to remove button shadow (android)

前端 未结 10 1854
失恋的感觉
失恋的感觉 2020-12-07 11:16

I want to remove the shadow from the button to make it seem more flat.

I have this right now:

\"cancel

相关标签:
10条回答
  • 2020-12-07 11:41

    the @Alt-Cat answer work for me!

    R.attr.borderlessButtonStyle doesn't contain shadow.

    and the document of button is great.

    Also, you can set this style on your custom button, in second constructor.

        public CustomButton(Context context, AttributeSet attrs) {
            this(context, attrs, R.attr.borderlessButtonStyle);
        }
    
    0 讨论(0)
  • 2020-12-07 11:45

    Another alternative is to add

    style="?android:attr/borderlessButtonStyle"
    

    to your Button xml as documented here http://developer.android.com/guide/topics/ui/controls/button.html

    An example would be

    <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" />
    
    0 讨论(0)
  • 2020-12-07 11:48

    I use a custom style

    <style name="MyButtonStyle" parent="@style/Widget.AppCompat.Button.Borderless"></style>
    

    Don't forget to add

    <item name="android:textAllCaps">false</item>
    

    otherwise the button text will be in UpperCase.

    0 讨论(0)
  • 2020-12-07 11:48

    All above answers are great, but I will suggest an other option:

    <style name="FlatButtonStyle" parent="Base.Widget.AppCompat.Button">
     <item name="android:stateListAnimator">@null</item>
     <!-- more style custom here --> 
    </style>
    
    
    
    0 讨论(0)
提交回复
热议问题