Search code examples
androidandroid-support-libraryandroid-textinputlayout

Preventing TextInputLayout from making TextInputEditText taller


I want that password toggle feature, and it seems TextInputLayout has that feature, not TextInputEditText. But as you see the code below, even though I set the height to wrap_content and app:hintEnabled="false", the height of TextInputEditTextgets taller if the TextInputEditText is in TextInputLayout. Compare that to the height of the TextInputEditText outside the TextInputLayout.

Since I do not use that hint animation, there is no need that the TextInputLayout to increase the height of TextInputEditText. How can I prevent TextInputLayout from increasing the height of TextInputEditText?

Screenshot of an emulator screen.

<?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>

Solution

  • Only solution I have found so far is to set android:layout_height to fixed size. For example 40dp.