gpt4 book ai didi

Android setError() 保持空白

转载 作者:行者123 更新时间:2023-11-29 16:08:47 26 4
gpt4 key购买 nike

我有这几行代码来验证表单输入。然而,它不输出任何东西——只是一个空白框。请问我错过了什么?

 public void onClick(View view)
{
if( view.getId() == R.id.btnLogin )
{
TestClass.setUsername( txtUserName.getEditableText().toString() );
TestClass.setPassword( txtPassword.getEditableText().toString() );

if( TestClass.getUsername().toString().length() == 0 )
{
this.txtUserName.setError( "Incorrect input!" );
}
else if( TestClass.getPassword().toString().length() == 0 )
{
this.txtPassword.setError( "Incorrect input!" );
}
else
{
// do the login stuff here
}
}
}

最佳答案

试试这个,

int ecolor = Color.RED; // whatever color you want
String estring = "Input is incorrect"; // your error message
ForegroundColorSpan fgcspan = new ForegroundColorSpan(ecolor);
SpannableStringBuilder ssbuilder = new SpannableStringBuilder(estring);
ssbuilder.setSpan(fgcspan, 0, estring.length(), 0);
myedittext.setError(ssbuilder);

来源:Android EditText.setError() yields invisible error text

关于Android setError() 保持空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15361983/

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