How to remove padding around buttons in Android?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Removing apparent padding around an Android button is harder than setting one XML attribute, because the extra space may come from internal padding, minimum size rules, or the default background drawable. The correct fix is to identify which layer is adding space and then override that layer intentionally. If you only set padding="0dp", the button may still look like it has margins or invisible insets.
Know the Three Usual Sources of Extra Space
When a button looks padded, the cause is usually one of these:
- actual content padding inside the view
- minimum width or height applied by the widget style
- insets or transparent space baked into the default background drawable
That is why visual space around a button can survive even after all four padding values are set to zero.
Start With Explicit Padding and Size Defaults
For a plain Button, begin by resetting the obvious values:
This removes explicit internal padding and prevents the widget from reserving extra size through default minimum dimensions.
In many cases that is enough. When it is not, the background is usually responsible.
Replace the Default Background When Insets Are the Real Issue
Framework and AppCompat button backgrounds often contain built-in visual padding or optical insets. If your design needs a tighter shape, supply your own drawable background.
Example background drawable:
Apply it:
Notice the difference: you are no longer fighting the system default background. You are defining exactly how much space the content should have.
Special Case: MaterialButton
If you are using Material Components, MaterialButton adds another layer of spacing control through its inset attributes. Those can make the button appear larger than expected even when padding is already minimal.
If the project uses Material theming, check insets before assuming the layout is wrong.
Keep Accessibility in Mind
Removing visual padding does not mean shrinking the tap target until it becomes hard to use. Android guidance generally expects touch targets around 48dp. If you make the button look compact, consider keeping surrounding layout space or using a container that preserves a reasonable hit area.
A button that looks elegant but is difficult to tap is usually a regression, not an improvement.
Debugging: Find Out What Is Really Taking Space
If the button still looks too large, inspect these values one at a time:
- '
padding' - '
minWidth' - '
minHeight' - background drawable
- parent layout margins
A common mistake is blaming the button for space that actually comes from the parent layout's margins or constraints.
Common Pitfalls
- Setting
padding="0dp"and expecting that to remove background insets. - Forgetting
minWidthandminHeight, which can keep the button larger than expected. - Using
MaterialButtonwithout checking its inset attributes. - Replacing the background without restoring enough internal spacing for readable text.
- Making the button visually tiny and accidentally hurting accessibility.
Summary
- Extra button space can come from padding, minimum size, or background insets.
- Reset
padding,minWidth, andminHeightfirst. - If the default background still adds space, replace it with your own drawable.
- For
MaterialButton, also inspectapp:insetTop,app:insetBottom,app:insetLeft, andapp:insetRight. - Keep touch-target usability in mind even when the design needs a compact button.

