Android
Button Padding
UI Design
Android Development
Mobile App Design

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:

xml
1<Button
2    android:id="@+id/saveButton"
3    android:layout_width="wrap_content"
4    android:layout_height="wrap_content"
5    android:padding="0dp"
6    android:minWidth="0dp"
7    android:minHeight="0dp"
8    android:text="Save" />

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:

xml
1<!-- res/drawable/button_compact.xml -->
2<shape xmlns:android="http://schemas.android.com/apk/res/android"
3    android:shape="rectangle">
4    <solid android:color="#1565C0" />
5    <corners android:radius="8dp" />
6</shape>

Apply it:

xml
1<Button
2    android:id="@+id/saveButton"
3    android:layout_width="wrap_content"
4    android:layout_height="wrap_content"
5    android:background="@drawable/button_compact"
6    android:paddingLeft="12dp"
7    android:paddingTop="6dp"
8    android:paddingRight="12dp"
9    android:paddingBottom="6dp"
10    android:minWidth="0dp"
11    android:minHeight="0dp"
12    android:text="Save"
13    android:textColor="#FFFFFF" />

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.

xml
1<com.google.android.material.button.MaterialButton
2    android:id="@+id/filterButton"
3    android:layout_width="wrap_content"
4    android:layout_height="wrap_content"
5    android:minWidth="0dp"
6    android:minHeight="0dp"
7    android:paddingLeft="10dp"
8    android:paddingTop="4dp"
9    android:paddingRight="10dp"
10    android:paddingBottom="4dp"
11    app:insetTop="0dp"
12    app:insetBottom="0dp"
13    app:insetLeft="0dp"
14    app:insetRight="0dp"
15    android:text="Filter" />

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 minWidth and minHeight, which can keep the button larger than expected.
  • Using MaterialButton without 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, and minHeight first.
  • If the default background still adds space, replace it with your own drawable.
  • For MaterialButton, also inspect app:insetTop, app:insetBottom, app:insetLeft, and app:insetRight.
  • Keep touch-target usability in mind even when the design needs a compact button.

Course illustration
Course illustration

All Rights Reserved.