How can I remove all default padding from EditText?

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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"              /> 

回答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"     ... /> 


回答2:

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

<EditText     ...     android:layout_marginLeft="-4dp"     android:layout_marginRight="-4dp"     ... /> 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!