2

How can I remove the default margin Android buttons are using? I want the buttons to have full width (no space at all between the edge of the screen and the button) and no space between them. I am not setting any padding but they seem to have one.

I am using "Theme.AppCompat.Light.NoActionBar" as my app theme parent.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

Screenshot showing the default margin android buttons have

netcyrax
  • 1,079
  • 1
  • 13
  • 27

3 Answers3

2

I had the same problem. The default button comes with margins. Set a button property like this:

android:layout_marginTop="-3dp"

Do the same for the left, right, and bottom margins. Or define a new drawable with these parameters:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:padding="10dp"
    >
    <solid android:color="@color/colorButtonGray"/>
    <corners
        android:bottomRightRadius="2dp"
        android:bottomLeftRadius="2dp"
        android:topLeftRadius="2dp"
        android:topRightRadius="2dp"/>
</shape> 

The custom shape will not have any built in margins.

Jay
  • 614
  • 5
  • 22
1

Use as below in the button xml, then change the other features this changes to how you want them displayed.

style="?android:attr/buttonBarButtonStyle"
Geoff
  • 583
  • 2
  • 7
  • 25
-3

you can use android:minHeight=0 android:minWidth=0 to remove extra marging from button.

Suchi
  • 116
  • 1
  • 11