简体   繁体   English

如何从 TextInputLayout 中删除底部填充

[英]How to remove bottom padding from TextInputLayout

The first picture is what I want.第一张图就是我想要的。 The second picture is what I have implemented.第二张图是我实现的。 As you can see, there is a padding to the bottom of the TextInputLayout which makes the gray background overflow past edittext line.如您所见,TextInputLayout 底部有一个填充,这使得灰色背景溢出编辑文本行。

Please do not suggest negative margin or padding as it does not work in newer APIs.请不要建议负边距或填充,因为它在较新的 API 中不起作用。

Here is the XML I have for the first text input layout.这是我用于第一个文本输入布局的 XML。

<android.support.design.widget.TextInputLayout
    android:id="@+id/fullNameTextLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="16dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="32dp"
    android:paddingTop="10dp"
    android:background="#EAEAEA"
    android:hint="Full Name"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <EditText
        android:id="@+id/fullNameEditText"
        style="@style/Regular15Grey1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapWords"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>

图片1 图2

You can using android:layout_marginBottom="-xdp" in your EditText您可以在 EditText 中使用android:layout_marginBottom="-xdp"

 <EditText
        android:id="@+id/fullNameEditText"
        style="@style/Regular15Grey1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textCapWords"
        android:paddingLeft="12dp"
        android:layout_marginBottom="-xdp"
        android:paddingRight="12dp"
        android:singleLine="true"/>

value of x depend on your design. x 的值取决于您的设计。

hope this helps希望这可以帮助

 <android.support.design.widget.TextInputLayout
        android:id="@+id/fullNameTextLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:paddingTop="10dp"
        android:hint="Full Name"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <EditText
            android:id="@+id/fullNameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textCapWords"
            android:text=""
            android:paddingBottom="16dp"
            android:paddingStart="8dp"
            android:paddingEnd="8dp"
            android:layout_marginBottom="-8dp"
            android:singleLine="true"/>
    </android.support.design.widget.TextInputLayout>

我发现填充实际上是错误文本的空间,如果您禁用错误(例如在布局 XML 中使用app:errorEnabled="false" )填充更接近您的期望。

Maybe add a 2dp line below the EditText也许在EditText下方添加一条2dp line

<View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="@android:color/black" />

You can change the color and the width later您可以稍后更改颜色和宽度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM