Remove padding around buttons in Android
Codemia Knowledge Hub ·
Extra space around an Android button is not always padding. It can come from real padding, MaterialButton insets, minimum size rules or the background drawable, which is why android:padding="0dp" sometimes seems to do nothing. Find which layer adds the space and clear that one.
Set the padding to zero
For a standard Button, start with explicit zero padding:
To change only some sides, set the individual edges:
This removes content padding inside the view, but not the other sources of spacing.
Changing padding at runtime
Useful when different screen states need different spacing, but it still only affects the view's padding values.
Clear MaterialButton insets
MaterialButton styles define insets, so zero padding alone may not flatten the spacing:
The inset attributes are often the missing piece when the button still looks padded.
Remove minimum width and height
Buttons can also look padded because they enforce a minimum size. For a very compact button, check:
On a MaterialButton, you may also need:
The exact fix depends on the widget type and style.
Replace a background drawable that adds space
Even with zero padding and insets, the background can contain visual margins or rounded shapes that push the content away from the edge. If the built-in background fights your layout, use a simpler background drawable rather than more padding tweaks. This comes up often with icon-only or compact chip-like buttons.
Keep a usable touch target
A visually compact button still needs a practical touch target. Removing every bit of apparent padding can make a button hard to tap even if it looks precise, so ask whether the control will still be easy to use.
Why the change seems ignored
android:padding="0dp"does not remove Material insets, minimum size or background shape.- The real spacing may come from the applied theme or component style rather than the attribute you edited. Inspect the widget type and style.
Button,AppCompatButtonandMaterialButtonhave similar but not identical defaults, so a fix for one may not apply to another.
Related reading
- How to remove provisioning profiles from Xcode
- How to remove the default Navigation Bar space in SwiftUI NavigationView
- How to remove the last border of the last cell in UITableView?
- How to remove the left and right Padding of a List in SwiftUI?
- How to remove the Xcode warning Apple Mach-O Linker Warning 'Pointer not aligned at address
- How to render a PDF file in Android
- How to replicate background-attachment fixed on iOS
- How to require an enum be defined in Swift Protocol
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.