How to remove border/shadow from lollipop buttons

前端 未结 11 1521
借酒劲吻你
借酒劲吻你 2020-12-12 19:21

The buttons looks fine for api < 21. However, the +21 versions creates this border or shadow that is shown on the image below. How do I get rid of it without changeing th

相关标签:
11条回答
  • 2020-12-12 19:37

    You can create an xml drawable with button color and set it as a background of the button

    0 讨论(0)
  • 2020-12-12 19:43

    I would suggest you just remove the shadow entirely, by setting the elevation to nothing. Since you already have a XML style (add this to use this universally), or you could add this attribute to your XML view definition

    android:elevation="0dp"
    
    0 讨论(0)
  • 2020-12-12 19:45

    There is already a style you can leverage not to have the borders.

    apply

    style="@style/Base.Widget.AppCompat.Button.Borderless" 
    

    to your item to remove the borders

    0 讨论(0)
  • 2020-12-12 19:47

    Best and easiest way i am using is setting style attribute to Button

    <Button
    ...
    style="?android:attr/borderlessButtonStyle"
    ....
    /> 
    

    may be someone need in future.

    0 讨论(0)
  • 2020-12-12 19:47

    in xml we can use

    android:stateListAnimator="@null"
    
    0 讨论(0)
  • 2020-12-12 19:48

    Lollipop has a nasty little feature called stateListAnimator which handles the elevations on Buttons, which leads to shadows.

    Remove the stateListAnimator to get rid of the shadows.

    You have got multiple options to do that:

    Java:

    button.setStateListAnimator(null);
    

    Kotlin:

    button.stateListAnimator = null
    

    or in your layout xml's:

    <Button
    ...
    android:stateListAnimator="@null" 
    ....
    /> 
    
    0 讨论(0)
提交回复
热议问题