2 подсказки появляются, когда TextInputLayout сфокусирован - PullRequest
0 голосов
/ 10 мая 2019

У меня возникли проблемы с TextInputLayout.

Когда фокус TextInputLayout сфокусирован, я вижу, что текст подсказки всплывает над текстовым полем, а также остается в текстовом поле. Прикрепленные изображения: enter image description here

И когда я набираю материал в поле, текст накладывается на подсказку в текстовом поле.

enter image description here

Это XML для моего TextInputLayout

 <com.google.android.material.textfield.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        app:layout_constraintTop_toBottomOf="@+id/imageView" app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="32dp" app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="32dp" android:id="@+id/email"
        android:hint="hint">

    <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

Я использую библиотеку компонентов материала Android следующим образом:

реализация 'com.google.android.material: материал: 1.0.0'

Как я могу получить подсказку TextInputLayout, которая будет скрыта, если на ней есть текст?

Вот полный макет:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/login"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.login.login.LoginFragment">
<ImageView
        android:layout_width="279dp"
        android:layout_height="289dp"
        android:src="@drawable/react"
        android:id="@+id/imageView" app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
        app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
        android:layout_marginTop="24dp" app:layout_constraintTop_toTopOf="parent"
        android:contentDescription="@string/vitrix_logo"/>
<com.google.android.material.button.MaterialButton
        android:text="@string/login"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/loginButton"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="32dp" app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="32dp" android:contentDescription="@string/click_to_login_to_the_app"
        app:layout_constraintHorizontal_bias="0.0"
        android:layout_marginBottom="16dp" app:layout_constraintBottom_toTopOf="@+id/createNewAccount"/>
<com.google.android.material.button.MaterialButton
        android:text="@string/create_account"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/createNewAccount"
        app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="32dp" app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="32dp" app:layout_constraintHorizontal_bias="0.0"
        android:layout_marginBottom="32dp" app:layout_constraintBottom_toBottomOf="parent"/>
<com.google.android.material.textfield.TextInputLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        app:layout_constraintTop_toBottomOf="@+id/imageView" app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="32dp" app:layout_constraintStart_toStartOf="parent"
        android:layout_marginStart="32dp" android:id="@+id/email"
        android:hint="hint">

    <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>

Базовый макет деятельности

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginActivity">


<fragment
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:navGraph="@navigation/navigation_graph" app:defaultNavHost="true"
        android:id="@+id/fragment" android:layout_marginStart="8dp"
        app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="8dp"
        app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
        android:layout_marginEnd="8dp" android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"/>

Ответы [ 4 ]

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

Оказывается, я просто загружал фрагмент дважды.

Я загружал во Фрагмент один раз, используя компоненты навигации, и второй раз из автоматически сгенерированного стандартного кода основной активности, который вы получаете, когда используете шаблон Действие + Фрагмент.

Чтобы решить эту проблему, просто удалите FragmentTrancaction.replace из своей основной деятельности и позвольте компоненту Nav загрузить этот фрагмент для вас.

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

Попробуйте использовать android.support.design.widget.TextInputLayout intead of com.google.android.material.textfield.TextInputLayout.

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

попробуйте это,

  <android.support.design.widget.TextInputLayout
    android:id="@+id/input_mobnumber_box"
    android:layout_width="320dp"
    android:layout_gravity="center"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/input_mobnumber"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-light"
        android:hint="Mobile Number" />

</android.support.design.widget.TextInputLayout>
0 голосов
/ 10 мая 2019

Лучший способ достичь ожидаемого результата:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Full name">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/etFullName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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