代码:
<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#setError
或AutoCompleteTextView#error
时的结果:
答案 0 :(得分:1)
您需要在TextInputLayout上使用setError()而不是EditText。
TextInputLayout textInputLayout = view.findViewById(R.id.textInputLayout);
textInputLayout.setError("Password cannot be empty.");