Подтвердить что ты не робот

Просмотр Android EditText Плавающая подсказка в дизайне материалов

Предоставляет ли API 21 метод для использования следующей функции:

http://www.google.com/design/spec/components/text-fields.html#text-fields-floating-labels

Я пытаюсь загрузить подсказки EditText.

Спасибо!

4b9b3361

Ответ 1

Плавающая подсказка EditText:

Добавьте зависимость ниже в gradle:

compile 'com.android.support:design:22.2.0'

В макете:

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

        <EditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="UserName"/>
    </android.support.design.widget.TextInputLayout>

Ответ 2

Да, по состоянию на 29 мая 2015 г. эта функциональность теперь предоставляется в Библиотеке поддержки дизайна Android.

В эту библиотеку включена поддержка

  • Плавающие метки
  • Кнопка плавающего действия
  • Snackbar
  • Ящик для навигации
  • и более

Ответ 3

Библиотека поддержки Android может быть импортирована в пределах gradle в зависимостях:

    compile 'com.android.support:design:22.2.0'

Он должен быть включен в GradlePlease! И как пример, чтобы использовать его:

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

    <AutoCompleteTextView
        android:id="@+id/autoCompleteTextViewTo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="To"
        android:layout_marginTop="45dp"
        />
</android.support.design.widget.TextInputLayout>

Btw, редактор может не понимать, что AutoCompleteTextView разрешен в TextInputLayout.

Ответ 4

Android не предоставил собственный метод. Не AppCompat.

Попробуйте эту библиотеку: https://github.com/rengwuxian/MaterialEditText

Это может быть то, что вы хотите.

Ответ 5

Импортируйте библиотеки поддержки. В файле проекта build.gradle добавьте следующие строки в зависимости от проекта:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
}

Используйте следующий TextInputLayout в своем макете пользовательского интерфейса:

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

    <EditText
        android:id="@+id/username"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:hint="Username"/>

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

Затем вызовите setHint в TextInputLayout сразу после вызова setContentView, потому что для анимации плавающей метки вам просто нужно установить подсказку, используя метод setHint.

final TextInputLayout usernameWrapper = (TextInputLayout) findViewById(R.id.usernameWrapper);
usernameWrapper.setHint("Username");

Ответ 6

@anduboy предложение https://gist.github.com/chrisbanes/11247418, вероятно, лучший выбор.

https://github.com/thebnich/FloatingHintEditText работает с appcompat-v7 v21.0.0, но так как v21.0.0 не поддерживает цвета акцентов с подклассами EditText, подчеркивание FloatingHintEditText будет по умолчанию сплошным черным или белым. Кроме того, прокладка не оптимизирована для стиля материала EditText, поэтому вам может потребоваться его настройка.

Ответ 8

Попробуйте этот путь

введите описание изображения здесь

  dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'

}

для получения дополнительной информации нажмите здесь

Ответ 9

Для более простого способа использования InputTextLayout я создал эту библиотеку, которая сокращает ваш XML-код до половины, а также предоставляет вам возможность устанавливать сообщение об ошибке, а также подсказку и простой способ выполнять ваши проверки. https://github.com/TeleClinic/SmartEditText

Просто добавьте

compile 'com.github.TeleClinic:SmartEditText:0.1.0'

Затем вы можете сделать что-то вроде этого:

<com.teleclinic.kabdo.smartmaterialedittext.CustomViews.SmartEditText
    android:id="@+id/emailSmartEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:setLabel="Email"
    app:setMandatoryErrorMsg="Mandatory field"
    app:setRegexErrorMsg="Wrong email format"
    app:setRegexType="EMAIL_VALIDATION" />

<com.teleclinic.kabdo.smartmaterialedittext.CustomViews.SmartEditText
    android:id="@+id/passwordSmartEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:setLabel="Password"
    app:setMandatoryErrorMsg="Mandatory field"
    app:setPasswordField="true"
    app:setRegexErrorMsg="Weak password"
    app:setRegexType="MEDIUM_PASSWORD_VALIDATION" />

<com.teleclinic.kabdo.smartmaterialedittext.CustomViews.SmartEditText
    android:id="@+id/ageSmartEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:setLabel="Age"
    app:setMandatory="false"
    app:setRegexErrorMsg="Is that really your age :D?"
    app:setRegexString=".*\\d.*" />