How to write style to error text of EditText in android?

前端 未结 7 1826
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 12:37

I\'m trying to write new custom style for my android application. I need to give style to errorText which appears after setting setError in EditText

7条回答
  •  感动是毒
    2020-11-27 13:07

    Please add it at the time of form validation if edit text field is blank.

                int ecolor = R.color.black; // whatever color you want
            String estring = "Please enter a valid email address";
            ForegroundColorSpan fgcspan = new ForegroundColorSpan(ecolor);
            SpannableStringBuilder ssbuilder = new SpannableStringBuilder(estring);
            ssbuilder.setSpan(fgcspan, 0, estring.length(), 0);
    
            edtEmail.requestFocus();
            edtEmail.setError(ssbuilder); 
    

    when you write in edit text, error sign automatic goes off

    Thanks Sachin

提交回复
热议问题