使用TextInputLayout和TextInputEditText时删除多余的空间/填充/边距

时间:2019-10-15 06:34:32

标签: android android-textinputlayout material-components material-components-android

我要删除下图所示的多余空间。

https://imgur.com/T5IzbKe

这是我的xml:

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/sh_layout_mobile"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="20dp"
        android:layout_marginTop="28dp"
        android:layout_marginEnd="20dp"
        android:background="@drawable/gradient_back"
        app:boxBackgroundMode="outline"
        app:hintEnabled="false"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView9">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:drawableEnd="@drawable/ic_phone"
            android:drawableTint="@color/white"
            android:drawableTintMode="multiply"
            android:drawingCacheQuality="high"
            android:fontFamily="@font/roboto"
            android:hint="@string/mobile_number"
            android:inputType="textPersonName"
            android:paddingRight="0dp"
            android:textColor="@color/white"
            android:textColorHighlight="@color/white"
            android:textColorHint="@color/white"
            android:textColorLink="@color/white"
            android:textSize="15dp" />

    </com.google.android.material.textfield.TextInputLayout>

我想要的是最小化或完全去除顶部空间或边距或填充。我尝试了一下,并调整了一些设置,但没有任何效果。

1 个答案:

答案 0 :(得分:0)

为editText制作样式,以删除填充

 <style name="styleTextInputEditText" parent="Base.Widget.MaterialComponents.TextInputEditText">
    <item name="android:paddingStart">0dp</item>
    <item name="android:paddingEnd">0dp</item>
    <item name="android:paddingTop">0dp</item>
    <item name="android:paddingBottom">0dp</item>
    .....
</style>

并将其分配给您的textInputLayout editText

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/yourId"
    style="@style/styleTextInput"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    ....>

    <com.google.android.material.textfield.TextInputEditText
        style="@style/styleTextInputEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        .... />
</com.google.android.material.textfield.TextInputLayout>