Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of text inside setError method?

Tags:

android

I am currently using an Android application where I am using the setError method for EditText validation. The problem is that I want to change the color of the text inside the method.

 EditText UserNameEdt, PasswordEdt;
 String UserName;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.login);
     UserName = UserNameEdt.getText().toString();
     Password = PasswordEdt.getText().toString();

     if (UserName.equals("")) {
         UserNameEdt.setError("Enter UserName");    
     } 
 }

I want to change the color of string "enter username" into black, not the text inside the EditText.

like image 566
user1057197 Avatar asked Dec 13 '25 13:12

user1057197


1 Answers

Error text with app theme color:

UserNameEdt.setError("Enter UserName");

You can use an HTML tag to change text color. Set like below:

UserNameEdt.setError(Html.fromHtml("<font color='green'>hello</font>"));
like image 58
abh22ishek Avatar answered Dec 15 '25 06:12

abh22ishek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!