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"
... />
Related videos on Youtube
Author by
Jim
Updated on June 06, 2022Comments
-
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.
Addingandroid:includeFontPadding="false"
did not help and using negativeandroid:layout_marginLeft
orandroid:layout_marginRight
just makes theEditText
"expand".
How can I strip all padding from theEditText
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 almost 9 yearsSome, if not all, of that is coming from the background, particularly if the background is a nine-patch PNG file.
-
dieter_h almost 9 yearsSet:
android:padding="0dp" android:background="@null" tools:text="test test"
-
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 over 7 yearsSo easy, so it just has some non-zero padding by default.
-
Franco over 6 yearsThis 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 over 6 yearsTry adding android:paddingBottom="0dp" (developer.android.com/reference/android/view/…)
-
Juan Ignacio Barisich almost 5 yearsFranco's comment is right. This answer is not valid for me.
-
Ivan Syabro about 3 yearsSometimes negative margin isn't a got idea. I faced problems with context popup menu appearance on some Samsung devices
-
Ian almost 3 yearshow can you do this with xml?
-
Ivan Syabro almost 3 years@lan I think there is no way to do this in pure xml