TextInputLayout содержит EditText, который, в свою очередь, получает ввод от пользователя. С TextInputLayout, представленным в библиотеке поддержки дизайна Android, мы должны установить ошибку TextInputLayout, содержащую EditText, а не сам EditText. При написании пользовательский интерфейс будет ориентирован только на EditText, а не на весь TextInputLayout, что может привести к тому, что клавиатура закроет ошибку. В следующем GIF обратите внимание, что пользователь должен сначала удалить клавиатуру, чтобы увидеть сообщение об ошибке. Это в сочетании с настройкой действий IME для перемещения по клавиатуре приводит к действительно запутанным результатам.
Макет XML-кода:
<android.support.design.widget.TextInputLayout
android:id="@+id/uid_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
android:layout_marginTop="8dp">
<EditText
android:id="@+id/uid_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:hint="Cardnumber"
android:imeOptions="actionDone"/>
</android.support.design.widget.TextInputLayout>
Java-код, устанавливающий ошибку в TextInputLayout:
uidTextInputLayout.setError("Incorrect cardnumber");
Как я могу убедиться, что сообщение об ошибке видно, а пользователь не пытается его увидеть? Можно ли сместить фокус?