Search code examples
androidbuttonandroid-5.0-lollipop

How to remove border/shadow from lollipop buttons


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 the hole theme, but setting a style variable?

enter image description here

It might be more clear on this colored image. There is some kind of border around the buttons. enter image description here

My buttonssstyle is defined like this:

<style name="buttonTransparent" parent="Base.TextAppearance.AppCompat.Button">
        <item name="android:background">#00000000</item>
        <item name="android:textColor">@drawable/button_text_blue</item>
        <item name="android:textSize">18dp</item>
        <item name="android:textAllCaps">false</item>
        <item name="android:minHeight">45dp</item>
    </style>

<style name="buttonLargeWhite" parent="buttonTransparent">
        <item name="android:background">#FFF</item>
        <item name="android:layout_marginTop">10dp</item>
    </style>

Solution

  • 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" 
    ....
    />