Preventing TextInputLayout from making TextInputEditText taller

久未见 提交于 2019-12-23 12:28:11

问题


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?

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

来源:https://stackoverflow.com/questions/49707950/preventing-textinputlayout-from-making-textinputedittext-taller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!