Хотите настроить атрибут EditText с подсказкой - PullRequest
0 голосов
/ 25 октября 2019

Я новичок в разработке мобильных Android и Java. И интересно, если кто-нибудь может помочь мне с моей проблемой.

Теперь я создаю файл XML для моего приложения для Android и хочу, чтобы он отображал что-то похожее ниже.

enter image description here

Можно ли сделать это в файле XML без глубоких знаний Java? Я просто хочу иметь фиксированный текст в своем атрибуте EditText. Использование LinearLayout для моего первого приложения. Я ценю любую помощь.

Использование API 28 для тестирования.

Ответы [ 3 ]

0 голосов
/ 25 октября 2019

Да, есть макет по умолчанию TextInputLayout и TextInputEditText. Вот документация: https://developer.android.com/reference/android/support/design/widget/TextInputLayout https://material.io/develop/android/components/text-input-layout/

0 голосов
/ 25 октября 2019

Вы ищете TextInputLayout компонент:

  <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Username"
        app:boxBackgroundColor="@color/white"
        app:boxStrokeColor="@color/text_input_layout_stroke_color"
        app:counterMaxLength="15"
        app:counterEnabled="true"
        >

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

    </com.google.android.material.textfield.TextInputLayout>

enter image description here enter image description here

0 голосов
/ 25 октября 2019

Это называется TextInputLayout.Read здесь . Демо-пример здесь

  <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:hintEnabled="true">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Username" />

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