本文介绍了防止TextInputLayout使TextInputEditText更高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要该密码切换功能,看来TextInputLayout具有该功能,而不是TextInputEditText.但是,正如您在下面的代码中看到的那样,即使我将高度设置为wrap_contentapp:hintEnabled="false",但是TextInputEditText的高度也会变高,如果TextInputEditTextTextInputLayout中.将其与TextInputLayout之外的TextInputEditText的高度进行比较.

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.

由于我不使用该提示动画,因此不需要TextInputLayout来增加TextInputEditText的高度.如何防止TextInputLayout增加TextInputEditText的高度?

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>

推荐答案

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

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

这篇关于防止TextInputLayout使TextInputEditText更高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 17:12