防止TextInputLayout使TextInputEditText变高

5
我希望有一个密码切换功能,而TextInputLayout似乎具备此功能,但并非TextInputEditText。但是,如下所示的代码,即使我将高度设置为wrap_content并且app:hintEnabled="false",如果TextInputEditText位于TextInputLayout中,则TextInputEditText的高度会变高。与TextInputLayout外部的TextInputEditText相比较,其高度也不同。
由于我没有使用提示动画,因此TextInputLayout没有必要增加TextInputEditText的高度。我该如何防止TextInputLayout增加TextInputEditText的高度?

模拟器屏幕截图。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="121dp"
        android:background="#66FF0000"
        android:text="Normal EditText"
        android:inputType="textEmailAddress"/>

    <android.support.design.widget.TextInputLayout
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="196dp"
        app:hintEnabled="false"
        app:passwordToggleEnabled="true">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#660000FF"
            android:hint="TextInputEditText inside TextInputLayout"
            android:inputType="textPassword"/>
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputEditText
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="#6600FF00"
        android:hint="TextInputEditText"
        android:inputType="textPassword"/>

</RelativeLayout>
1个回答

1
到目前为止,我找到的唯一解决方案是将android:layout_height设置为固定大小,例如40dp。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接