How can I remove all default padding from EditText?

17,173

Solution 1

To remove the padding on the left and right of the EditText, you can use the following:

<EditText
    ...
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    ... />

Solution 2

If you also want to remove underline padding add negative margin:

<EditText
    ...
    android:layout_marginLeft="-4dp"
    android:layout_marginRight="-4dp"
    ... />
Share:
17,173

Related videos on Youtube

Jim
Author by

Jim

Updated on June 06, 2022

Comments

  • Jim
    Jim almost 2 years

    I am using an EditText and it always adds a bit of padding in my text to both left and right.
    Adding android:includeFontPadding="false" did not help and using negative android:layout_marginLeft or android:layout_marginRight just makes the EditText "expand".
    How can I strip all padding from the EditText that is being added by default?

    <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="20dp"
                android:fontFamily="roboto-regular"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"
                android:layout_marginLeft="-5dp"
                android:layout_marginRight="-5dp"
                android:includeFontPadding="false"
                android:textSize="@dimen/size"
                android:textColor="@color/color"
                android:inputType="textCapWords"
                android:hint="@string/hint"
                android:editable="false"
    
                />
    
    • CommonsWare
      CommonsWare almost 9 years
      Some, if not all, of that is coming from the background, particularly if the background is a nine-patch PNG file.
    • dieter_h
      dieter_h almost 9 years
      Set: android:padding="0dp" android:background="@null" tools:text="test test"
    • CommonsWare
      CommonsWare almost 9 years
      "I am not using any background" -- yes, you are. You are not changing the background. Hence, you are getting the standard background for whatever theme you are using.
  • Makalele
    Makalele over 7 years
    So easy, so it just has some non-zero padding by default.
  • Franco
    Franco over 6 years
    This will remove the padding for the text, but the line beneath it will still have a padding, which makes it look bad (at least in Android 8).
  • Tomasz Nguyen
    Tomasz Nguyen over 6 years
    Try adding android:paddingBottom="0dp" (developer.android.com/reference/android/view/…)
  • Juan Ignacio Barisich
    Juan Ignacio Barisich almost 5 years
    Franco's comment is right. This answer is not valid for me.
  • Ivan Syabro
    Ivan Syabro about 3 years
    Sometimes negative margin isn't a got idea. I faced problems with context popup menu appearance on some Samsung devices
  • Ian
    Ian almost 3 years
    how can you do this with xml?
  • Ivan Syabro
    Ivan Syabro almost 3 years
    @lan I think there is no way to do this in pure xml