Reputation: 489
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
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