Android Development
User Interface Design
Android Buttons
Coding Tips
Padding Removal

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:

xml
1<Button
2    android:id="@+id/myButton"
3    android:layout_width="wrap_content"
4    android:layout_height="wrap_content"
5    android:text="Click Me"
6    android:padding="0dp" />

To change only some sides, set the individual edges:

xml
1android:paddingStart="0dp"
2android:paddingEnd="0dp"
3android:paddingTop="0dp"
4android:paddingBottom="0dp"

This removes content padding inside the view, but not the other sources of spacing.

Changing padding at runtime

kotlin
val button: Button = findViewById(R.id.myButton)
button.setPadding(0, 0, 0, 0)

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:

xml
1<com.google.android.material.button.MaterialButton
2    android:id="@+id/materialButton"
3    android:layout_width="wrap_content"
4    android:layout_height="wrap_content"
5    android:text="Press Me"
6    android:padding="0dp"
7    android:insetTop="0dp"
8    android:insetBottom="0dp" />

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:

xml
android:minWidth="0dp"
android:minHeight="0dp"

On a MaterialButton, you may also need:

xml
1android:minWidth="0dp"
2android:minHeight="0dp"
3android:insetLeft="0dp"
4android:insetRight="0dp"

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, AppCompatButton and MaterialButton have similar but not identical defaults, so a fix for one may not apply to another.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Data 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.

Practice algorithms