
[英]keep getting this error when compiling xamarin android (mono for android) app
[英]Xamarin getting an error when using 'app:errorEnabled=“true”' to TextInputLayout
我正在尝试在 visual studio 中为应用程序创建一个注册页面,但每当我尝试将 app:errorEnabled="true" 添加到任何 TextInputLayouts 时,我都会收到一个错误,因为我的所有 ID 都不包含定义。 我删除它的那一刻,错误就消失了。
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/emailField"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:layout_marginHorizontal="23dp"
app:errorEnabled="true"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_marginBottom="15dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/emailTxt"
android:textColor="@color/white"
android:textSize="16sp"
android:inputType="textEmailAddress"/>
</android.support.design.widget.TextInputLayout>
在 C# 文件而不是 XML 文件中将 errorEnabled 设置为 true 解决了这个问题。
string fullName, phoneNum, email, password;
fullName = fullNameText.EditText.Text;
phoneNum = phoneText.EditText.Text;
email = emailtext.EditText.Text;
password = passwordText.EditText.Text;
if(fullName.Length <= 3)
{
fullNameText.ErrorEnabled = true;
fullNameText.Error = "Please enter a valid name";
return;
}
else if (!email.Contains("@"))
{
emailtext.ErrorEnabled = true;
emailtext.Error = "Please enter a valid email";
return;
}
else if(phoneNum.Length < 9)
{
phoneText.ErrorEnabled = true;
phoneText.Error = "Please enter a valid phone number";
return;
}
else if (password.Length < 8)
{
passwordText.ErrorEnabled = true;
passwordText.Error = "Password should be at least 8 characters long";
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.