EditText внутри TextInputLayout оставляет пустое место сверху - PullRequest
0 голосов
/ 07 июня 2018

У меня есть поле пароля, и я хотел реализовать функцию скрытия / отображения пароля.Поэтому я использовал TextInputLayout.Но если я использую EditText внутри TextInputLayout, он оставляет пустое место в верхней части макета.И мне нужно, чтобы высота этого поля пароля была меньше.С этим пробелом это невозможно.Я пытался установить высоту в отрицательное значение для EditText, но это не сработало.android: layout_height = "45dp" используется, чтобы уменьшить это поле, но оно не работает вообще.wrap_content делает его еще выше.

    <android.support.design.widget.TextInputLayout
            android:id="@+id/textInputLayout"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:layout_marginEnd="45dp"
            android:layout_marginStart="42dp"
            app:passwordToggleDrawable="@drawable/login_password_eye"
            app:passwordToggleEnabled="true">

            <EditText
                android:id="@+id/passwordTextField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:backgroundTint="@color/colorDivider"
                android:imeOptions="actionDone"
                android:inputType="textPassword"
                android:singleLine="true"
                android:textColor="@color/colorItemMajor"
                android:textSize="16sp" />

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

Изображение:

enter image description here

Код XML - полный (мне пришлось удалить цвета и изображения+ верхняя панель инструментов, но логика та же)

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mainLoginLayout"
    android:orientation="vertical"
    android:clickable="true"
    android:focusableInTouchMode="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/loginLayout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageLogin"
            android:layout_width="210dp"
            android:layout_height="210dp"
            android:layout_gravity="center"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher" />

        <TextView
            android:id="@+id/emailLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="E-mail"
            android:textColor="@color/colorBlack"
            android:textSize="16sp"
            android:layout_marginStart="45dp"
            android:layout_marginEnd="45dp"
            />

        <EditText
            android:id="@+id/emailTextField"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="45dp"
            android:layout_marginStart="45dp"
            android:backgroundTint="@color/colorBlack"
            android:inputType="textEmailAddress"
            android:textColor="@color/colorBlack"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/passwordLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Password"
            android:textColor="@color/colorBlack"
            android:textSize="16sp"
            android:layout_marginStart="45dp"
            android:layout_marginEnd="45dp"
            />

        <android.support.design.widget.TextInputLayout
            android:id="@+id/textInputLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/login_password_padding"
            android:layout_marginStart="@dimen/login_password_field_padding"
            app:passwordToggleDrawable="@drawable/login_password_eye"
            app:passwordToggleEnabled="true"
            app:passwordToggleTint="@android:color/black">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/passwordTextField"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="0dp"
                android:backgroundTint="@color/colorDivider"
                android:imeOptions="actionDone"
                android:inputType="textPassword"
                android:singleLine="true"
                android:textColor="@color/colorItemMajor"
                android:textSize="@dimen/login_password_label_textsize" />

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

        <LinearLayout
            android:id="@+id/default_login_button"
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:gravity="center"
            android:clickable="true"
            android:focusable="true"
            android:layout_height="55dp"
            android:layout_marginStart="45dp"
            android:layout_marginEnd="45dp"
            android:layout_marginTop="45dp"
            android:background="@color/colorBlack">

            <ImageView
                android:id="@+id/loginButtonIcon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center|center_horizontal"
                android:src="@mipmap/ic_launcher" />

            <TextView
                android:id="@+id/LoginButtonLabel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center|center_horizontal"
                android:text="Login"
                android:textAppearance="@style/FilledLoginButtonTextAppearance" />

        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Ответы [ 6 ]

0 голосов
/ 11 мая 2019

добавить нижний отступ к TextInputLayout

android:paddingBottom="11dp"
0 голосов
/ 07 июня 2018

Я думаю, вы видите это на предварительном просмотре макета.скомпилируйте его и попробуйте запустить, тогда вы увидите его рабочий гуд.Этот разрыв объясняется тем, что вы используете плавающий текст редактирования.- Харвиндер Сингх

Это сработало!

0 голосов
/ 07 июня 2018

Это мой код, связанный с вашей проблемой и ее правильной работой в проекте.попробуйте это по-своему и не забудьте прокомментировать.

       <android.support.design.widget.TextInputLayout
            android:id="@+id/input_Layout_Signup_Password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/input_Layout_Signup_Phone"
            app:passwordToggleEnabled="true"
            app:passwordToggleTint="@color/colorAccent"
            android:layout_margin="5dp">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/input_Signup_Password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:layout_marginRight="10dp"
                android:inputType="textPassword"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>
0 голосов
/ 07 июня 2018

Я думаю, вы должны использовать android.support.design.widget.TextInputEditText вместо EditText.

<android.support.design.widget.TextInputLayout
        android:id="@+id/textInputLayout"
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:layout_marginEnd="45dp"
        android:layout_marginStart="42dp"
        app:passwordToggleDrawable="@drawable/login_password_eye"
        app:passwordToggleEnabled="true">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/passwordTextField"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:backgroundTint="@color/colorDivider"
            android:imeOptions="actionDone"
            android:inputType="textPassword"
            android:singleLine="true"
            android:textColor="@color/colorItemMajor"
            android:textSize="16sp" />

 </android.support.design.widget.TextInputLayout>
0 голосов
/ 07 июня 2018

Используйте TextInputEditText вместо EditText

Специальный подкласс EditText, предназначенный для использования в качестве дочернего элемента TextInputLayout.

Использование этого класса позволяет отображатьподсказка в IME в режиме «извлечения».

0 голосов
/ 07 июня 2018

Поскольку вы сделали TextInputLayout, чтобы исправить его с помощью

 android:layout_height="45dp"

Пожалуйста, измените на wrap_content

...