TextInputLayout删除不需要的空间

时间:2019-07-25 07:39:33

标签: android android-layout material-design android-xml android-textinputlayout

我想要没有任何边框和框的TextInputLayout,所以我将以下代码用于

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/app_name"
        app:boxBackgroundMode="none"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

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

但是我不知道什么时候写

  

app:boxBackgroundMode =“ none”

对于TextInputLayout来说,大小是自动拉伸的,如果您发现有关此plz的任何解决方案对我有帮助,那么看起来就很奇怪。

这是我的输出的屏幕截图

enter image description here

1 个答案:

答案 0 :(得分:2)

这是因为app:boxBackgroundMode="none"

尝试以下代码来实现您的设计

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:backgroundTint="@color/white"
    app:boxStrokeColor="@color/white"
    app:boxBackgroundColor="@color/white"
    android:background="@color/white"
    android:hint="@string/app_name">

    <EditText
        android:background="@color/white"
        android:backgroundTint="@color/white"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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