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"
Related videos on Youtube
Comments
-
sousheel almost 2 years
I want to remove the shadow from the button to make it seem more flat.
I have this right now:
But I want this:
-
msamardzic about 9 yearsI write comment here, it's work for me. [stackoverflow.com/questions/27867284/… [1]: stackoverflow.com/questions/27867284/…
-
smileVann about 9 years
-
-
Juan José Melero Gómez over 8 yearsThis removes the button style, e.i. the shadow and emboss. Adding a selector with shapes is optional. This is a more accurate answer.
-
CACuzcatlan about 8 yearsCan you explain how this works? It didn't remove the drop shadow for me.
-
Tobliug about 8 yearsIn 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 about 8 yearsit replaces original background with shadows, with this background with solid color
-
GergelyPolonkai almost 8 yearsAlthough 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 over 7 yearsEasy and clean.
-
KoreanXcodeWorker almost 7 yearsWorked greatly to me
-
box almost 7 yearsThis isn't the correct answer, but you actually helped me to fix my issue with a similar problem, so thank you!
-
Rohit Kumar over 6 yearsaha! nice idea -- got me a quick fix --
-
Ayejuni Ilemobayo Kings about 5 yearsi love this method better, it's more flexible.
-
blueware about 5 years@Alon Kogan, is there any backward compatibility for using the
android:stateListAnimator
attribute? -
Juan José Melero Gómez almost 5 yearsThis solution allows you to create a style bot having to inherit from
borderlessButtonStyle
style, which gives you more flexibility. -
CoolMind almost 5 yearsIt is similar to Alon Kogan (stackoverflow.com/a/39122825/2914140).
-
CoolMind almost 5 yearsSometimes it is similar to stackoverflow.com/a/38004981/2914140, but a gray button in disabled state becomes lighter.
-
CoolMind over 4 yearsIt requires API 21.
-
zeroDivider over 4 yearshow is this different than 5ish of above?
-
ACAkgul over 4 yearsthis 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 about 4 yearsWorks on MaterialButton too
-
alexrnov almost 4 yearsRequires API level 21 or higher
-
jujuf1 over 3 yearsPerfect solution
-
abdu over 3 yearsafter settings stateListAnimator to null button becomes invisible, anyone experiencing this?
-
jerry about 3 yearsThis removes more than just the shadow.
-
marticztn about 3 yearsThis is a better solution for me, it keeps the ripple effect
-
QuarK about 3 yearsWhy I can't set this as
item
in buttonstyle
? -
Keith Mak over 2 yearsThanks for the solution! mind elaborate why tag works?