EditText错误图标并显示密码错误放置

我有一个EditText作为这样的密码输入


<android.support.design.widget.TextInputLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content">


            <EditText

                android:id="@+id/password"

                android:layout_width="match_parent"

                android:layout_height="wrap_content"

                android:hint="@string/prompt_password"

                android:imeActionId="@+id/login"

                android:imeActionLabel="@string/action_sign_in_short"

                android:imeOptions="actionUnspecified"

                android:inputType="textPassword"

                android:maxLines="1"

                android:singleLine="true" />


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

它可以正常工作,但是当出现错误时,错误图标会显示两次,并且位于显示密码图标的顶部。


错误图标放错了位置


我的验证代码显示错误:


if (success) {

    finish();

    startMainActivity();

} else {

         mPasswordView.setError(getString(R.string.error_incorrect_password));

            mPasswordView.requestFocus();

}


慕哥9229398
浏览 481回答 3
3回答

料青山看我应如是

不要叫setError上EditText,使用TextInputLayout的SETERROR()

HUH函数

材质版本1.1.0-alpha10的行为相同,即使您在TextInputLayout中设置了错误也是如此。您可以通过将以下行添加到TextInputLayout来避免这种情况:app:errorIconDrawable =“ @ null”

九州编程

使用此代码,您可以在显示错误时删除切换。您可以在用户编写任何内容时显示切换。不记得了,您应该给id输入文本布局public void showError(){&nbsp; &nbsp; password.setError(errorMessage);&nbsp; &nbsp; password.requestFocus();&nbsp; &nbsp; textInputLayout.setPasswordVisibilityToggleEnabled(false);}&nbsp;password.addTextChangedListener(new TextWatcher() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textInputLayout.setPasswordVisibilityToggleEnabled(true);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public void afterTextChanged(Editable editable) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });
打开App,查看更多内容
随时随地看视频慕课网APP