How to remove button shadow (android)

155,307

Solution 1

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

Solution 2

A simpler way to do is adding this tag to your button:

android:stateListAnimator="@null"

though it requires API level 21 or more..

Solution 3

Kotlin

stateListAnimator = null

Java

setStateListAnimator(null);

XML

android:stateListAnimator="@null"

Solution 4

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.

Solution 5

Material desing buttons add to button xml: style="@style/Widget.MaterialComponents.Button.UnelevatedButton"

Share:
155,307

Related videos on Youtube

sousheel
Author by

sousheel

i love lamp

Updated on July 30, 2022

Comments

  • sousheel
    sousheel almost 2 years

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

    I have this right now:

    cancel button with shadow

    But I want this:

    cancel button without shadow

  • Juan José Melero Gómez
    Juan José Melero Gómez over 8 years
    This removes the button style, e.i. the shadow and emboss. Adding a selector with shapes is optional. This is a more accurate answer.
  • CACuzcatlan
    CACuzcatlan about 8 years
    Can you explain how this works? It didn't remove the drop shadow for me.
  • Tobliug
    Tobliug about 8 years
    In addition, I use a custom style for my button. you can extend your custom style from : <style name="MyCustomButtonStyle" parent="Widget.AppCompat.Button.Borderless">
  • dlohani
    dlohani about 8 years
    it replaces original background with shadows, with this background with solid color
  • GergelyPolonkai
    GergelyPolonkai almost 8 years
    Although this may solve the OP’s problem, I’d recommend to add some context to it. Why will it help? Also, “try this” is a bit misleading. Are you sure it will solve the problem, or just guessing? If so, you should write a comment instead.
  • JCasso
    JCasso over 7 years
    Easy and clean.
  • KoreanXcodeWorker
    KoreanXcodeWorker almost 7 years
    Worked greatly to me
  • box
    box almost 7 years
    This isn't the correct answer, but you actually helped me to fix my issue with a similar problem, so thank you!
  • Rohit Kumar
    Rohit Kumar over 6 years
    aha! nice idea -- got me a quick fix --
  • Ayejuni Ilemobayo Kings
    Ayejuni Ilemobayo Kings about 5 years
    i love this method better, it's more flexible.
  • blueware
    blueware about 5 years
    @Alon Kogan, is there any backward compatibility for using the android:stateListAnimator attribute?
  • Juan José Melero Gómez
    Juan José Melero Gómez almost 5 years
    This solution allows you to create a style bot having to inherit from borderlessButtonStyle style, which gives you more flexibility.
  • CoolMind
    CoolMind almost 5 years
    It is similar to Alon Kogan (stackoverflow.com/a/39122825/2914140).
  • CoolMind
    CoolMind almost 5 years
    Sometimes it is similar to stackoverflow.com/a/38004981/2914140, but a gray button in disabled state becomes lighter.
  • CoolMind
    CoolMind over 4 years
    It requires API 21.
  • zeroDivider
    zeroDivider over 4 years
    how is this different than 5ish of above?
  • ACAkgul
    ACAkgul over 4 years
    this is only solution which is worked for me, borderlessButtonStyle tag didn't work, since I need to get rid off the shadow while button is being pressed
  • intips
    intips about 4 years
    Works on MaterialButton too
  • alexrnov
    alexrnov almost 4 years
    Requires API level 21 or higher
  • jujuf1
    jujuf1 over 3 years
    Perfect solution
  • abdu
    abdu over 3 years
    after settings stateListAnimator to null button becomes invisible, anyone experiencing this?
  • jerry
    jerry about 3 years
    This removes more than just the shadow.
  • marticztn
    marticztn about 3 years
    This is a better solution for me, it keeps the ripple effect
  • QuarK
    QuarK about 3 years
    Why I can't set this as item in button style?
  • Keith Mak
    Keith Mak over 2 years
    Thanks for the solution! mind elaborate why tag works?