如何使用EditText完全填充TextInputLayout?

时间:2018-06-18 17:32:25

标签: android android-layout android-edittext android-textinputlayout

enter image description here

我的EditText在TextInputLayout范围内。 我想要实现的是EditText完全在TextInputLayout内,以摆脱编辑字段顶部的空白区域。

这是布局:

 <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/login_edit_style"
        android:hint=" "> <!--android:hint=" "> if (TextUtils.isEmpty(mHint)) evaluates to false, and the EditText retains its hint.-->


        <EditText
            android:id="@+id/login"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_person"
            android:fontFamily="@font/montserrat"
            android:hint="Email"
            android:inputType="textEmailAddress"
            android:lineSpacingMultiplier="1.17"
            android:paddingLeft="@dimen/field_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:textColor="#4A4A4A"
            android:textColorHint="@color/colorPrimaryDark"
            android:textCursorDrawable="@drawable/cursor_colour"
            android:textSize="12sp" />

    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/login_edit_style"
        android:hint=" "> <!--if (TextUtils.isEmpty(mHint)) evaluates to false, and the EditText retains its hint.-->

        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/ic_locker"
            android:drawableRight="@drawable/ic_show_pass"
            android:ems="10"
            android:hint="Password"
            android:inputType="textPassword"
            android:lineSpacingMultiplier="1.17"
            android:paddingLeft="@dimen/field_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:textColor="#4A4A4A"
            android:textColorHint="@color/colorPrimaryDark"
            android:textCursorDrawable="@drawable/cursor_colour"
            android:textSize="12sp" />

    </android.support.design.widget.TextInputLayout>

1 个答案:

答案 0 :(得分:2)

顶部的空格用于当用户关注EditText时出现的浮动标签,如下所示:

enter image description here

如果您不想要浮动标签,请切换到仅使用EditText。另外,如果您使用的是TextInputLayout,则应该在其中使用TextInputEditText,而不仅仅是EditText