How to remove button shadow android
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
On Android, a button's "shadow" usually comes from elevation or from a state animator that changes elevation when the button is pressed. If you want a flatter design, removing the shadow is usually a matter of setting the elevation to zero and disabling any state-based elevation animation.
Where the Shadow Comes From
Modern Android views can cast a shadow when they have elevation. Material-styled buttons often use:
- '
android:elevationfor resting elevation' - '
android:stateListAnimatorfor press and release elevation changes' - a Material or AppCompat background that expects some elevation behavior
That is why setting only one property sometimes does not fully flatten the button.
XML Solution for a Flat Button
For a plain button on Android 5.0 and above, set the elevation to 0dp and disable the state list animator so pressed states do not add the shadow back:
This handles the two most common causes:
- no resting shadow
- no pressed-state shadow animation
If you want the same look across many buttons, define a reusable style:
Then apply it in the layout:
Programmatic Solution in Kotlin
If you need to toggle the effect dynamically, update the properties in code:
This is useful when a button should appear elevated in one screen state and flat in another.
MaterialButton Notes
If you are using MaterialButton, the same principle applies, but remember that Material Components may also style the background, ripple, insets, and shape. Elevation is still the main shadow mechanism, so zeroing it out is usually enough:
If the button still does not look flat, the issue is often not a shadow anymore. It may be:
- a tinted background
- inset padding that makes the button appear raised
- a custom style applied by the app theme
Older Android and Custom Backgrounds
On older Android versions, some "shadow-like" appearance may actually come from the button background drawable rather than real elevation. In that case, removing elevation does nothing because the effect is baked into the drawable.
A custom shape drawable is the usual fix:
Apply it as the button background:
This approach gives you full control over the visual result.
How to Debug the Remaining Effect
If a shadow still appears after setting elevation to zero, check these in order:
- Is
stateListAnimatorstill active? - Is a Material theme applying a component style you forgot about?
- Is the background drawable itself using gradients or padding that makes the button look raised?
- Are you looking at a ripple or overlay, not an actual shadow?
Treat the problem as a style stack, not as one magic attribute.
Common Pitfalls
The most common mistake is setting android:elevation="0dp" and stopping there. A pressed-state animator can still raise the button unless you also clear android:stateListAnimator.
Another mistake is assuming every dark edge is a shadow. Sometimes it is part of the background drawable or theme overlay.
Developers also forget API differences. Real elevation shadows are an Android 5.0 and later feature, while older visual effects may come from drawables.
Finally, if you are using MaterialButton, check whether the theme or style is reapplying properties after your layout attributes.
Summary
- Button shadows on Android usually come from elevation and state-based elevation animation.
- Set
android:elevation="0dp"to remove the resting shadow. - Set
android:stateListAnimator="@null"to prevent pressed-state shadows. - If the effect remains, inspect the background drawable and theme styles.
- For full control, use a custom flat background drawable.

