Connor Black
Connor Black

Reputation: 7181

setBackgroundColor method, android

Right now I'm building a simple form and I'm designing it so that if the user hasn't entered the necessary info before clicking the submit button the background turns red. And after if they have entered the correct info the form goes back to the way it was before.

// "if empty then set fields to red" checks
            if (firstLastName.getText().toString().equals("")) {
                firstLastName.setBackgroundColor(Color.RED);
            }
            else
                firstLastName.setBackgroundColor(Color.WHITE);
        }

The problem is that white apparently isn't what it was before, because it looks different. Is there a way to reset the form without deleting the info entered by the user?

If I'm not being clear please let me know and Ill try to elaborate.

Upvotes: 1

Views: 1496

Answers (1)

John Leehey
John Leehey

Reputation: 22240

How about setting and removing a color filter instead of changing the background color:

if (firstLastName.getText().toString().equals("")) {
    // 0xFFFF0000 is red
    firstLastName.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.DARKEN);}
else {
    //Setting to null removes filter
    firstLastName.getBackground().setColorFilter(null);
}

Upvotes: 1

Related Questions