gpt4 book ai didi

java - TextInputLayout setError() 没有出现在 fragment 中

转载 作者:行者123 更新时间:2023-11-30 05:01:19 44 4
gpt4 key购买 nike

我为 TextInputLayout 的 setError() 方法编写的文本没有出现在 fragment 中。尝试了各种解决方案,但没有一个奏效...

<itdgroup.myhomedoc.SignUpTextInputLayout
android:id="@+id/email_input_layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:errorTextAppearance="@style/error_appearance"
app:errorEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewAvenirBookFont">

<itdgroup.myhomedoc.CustomEditText
android:id="@+id/input_email"
android:layout_width="295dp"
android:layout_height="50dp"
android:layout_marginTop="11dp"
android:maxLines="1"
android:background="@drawable/custom_signup_edit_text"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:nextFocusDown="@+id/input_password"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:textSize="14sp"/>

</itdgroup.myhomedoc.SignUpTextInputLayout>
                String strUserName = eMail.getText().toString();
if(TextUtils.isEmpty(strUserName) || !isEmailValid(strUserName)) {
emailTIL.setError("Please enter valid email");
return;

这是自定义的 TextInputLayout

public class SignUpTextInputLayout extends TextInputLayout {
private Context context;

public SignUpTextInputLayout(Context context) {
super(context);
this.context = context;
}

public SignUpTextInputLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}

public SignUpTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.context = context;
}

@Override
protected void drawableStateChanged() {
super.drawableStateChanged();

EditText editText = getEditText();
if(editText != null) {
editText.setBackground(ContextCompat.getDrawable(this.context, R.drawable.custom_signup_edit_text));
}
}

@Override
public void setError(@Nullable final CharSequence error) {
super.setError(error);

EditText editText = getEditText();
if(editText != null) {
editText.setBackground(ContextCompat.getDrawable(this.context, R.drawable.error_signup_edit_text));
}
}
```

最佳答案

在您重写的 setError 方法中,也尝试添加 setError 方法:

@Override
public void setError(@Nullable final CharSequence error) {
super.setError(error);

EditText editText = getEditText();
if(editText != null) {
editText.setBackground(ContextCompat.getDrawable(this.context, R.drawable.error_signup_edit_text));
editText.setError("Please enter valid email");
}
}

关于java - TextInputLayout setError() 没有出现在 fragment 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58196561/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com