user1057197
user1057197

Reputation: 489

How to change color of text inside setError method?

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.

Upvotes: 2

Views: 6484

Answers (2)

abh22ishek
abh22ishek

Reputation: 2671

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>"));

Upvotes: 13

user1744952
user1744952

Reputation: 518

Try this:

UserNameEdt.setTextColor(Color.GREEN);

Upvotes: -3

Related Questions