眼睛指示器与AutoCompleteTextView

时间:2018-02-07 22:49:51

标签: java android kotlin material-design

代码:

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="match_parent"
    android:layout_height="52dp"
    android:background="@android:color/white"
    android:hint="@string/current_password"
    android:paddingEnd="14dp"
    android:paddingLeft="14dp"
    android:paddingRight="14dp"
    android:paddingStart="14dp"
    android:paddingTop="4dp"
    android:scrollbarAlwaysDrawHorizontalTrack="true"
    android:textColorHint="@color/darkBlue"
    app:layout_constraintTop_toBottomOf="@+id/toolbar"
    app:passwordToggleEnabled="true"
    app:passwordToggleTint="@color/colorAccent"
    tools:layout_editor_absoluteX="0dp">

    <AutoCompleteTextView
        android:id="@+id/actvCurrPass"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:textSize="15sp"
        tools:ignore="Deprecated,RtlHardcoded" />

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

调用AutoCompleteTextView#setErrorAutoCompleteTextView#error时的结果: enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要在TextInputLayout上使用setError()而不是EditText。

TextInputLayout textInputLayout = view.findViewById(R.id.textInputLayout);
textInputLayout.setError("Password cannot be empty.");