4

I have an editText and i want to set its background color to red like this:

 RegistrationCountry.setBackgroundColor(Color.RED);

Now i yould like to remove this background color. The problem using:

RegistrationCountry.setBackgroundColor(Color.TRANSPARENT);

Is that i will lose the Edittext outline.

Marvin Pinto
  • 30,138
  • 7
  • 37
  • 54
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
  • Are you asking: _if_ you set the background color to transparent, will you lose the EditText outline? In this case, have you tried it? What happened? – Marvin Pinto Feb 09 '12 at 15:18
  • Hi and thank you for the answer @Marvin. Yes, i am loosing it, that's the reason I am asking for the background deleting because I would not lose this outline. – Milos Cuculovic Feb 09 '12 at 15:30
  • Does that edit summarize what you need? (p.s. @Zakaria thanks for the edit - really helped to clear it up) – Marvin Pinto Feb 09 '12 at 15:55

3 Answers3

7

You can use

RegistrationCountry.setBackgroundResource(android.R.drawable.editbox_background);

To set the background to the standard background-image.

The problem arises when you call any of the setBackgroundX() methods, as this will replace the current background (i.e. the 'outline'), so when you call setBackgroundColor(Color.RED) you replace the outline with a red color, and then you replace the red with transparency. What you need to do is to replace the red with the original background, as can be done with the line above.

Jave
  • 31,598
  • 14
  • 77
  • 90
  • Thank you @Jave but this change anything, the probleé is that the transparence or the red colore will owerwrite the editbox_background. Any idea how to fix this? – Milos Cuculovic Feb 09 '12 at 16:11
  • Yes, don't set it to transparent, use this code *instead*. I edited my answer with a bit of an explanation. – Jave Feb 10 '12 at 08:57
  • Thank you Jave but I already tryed to do this and my RED coolor is still there. – Milos Cuculovic Feb 10 '12 at 09:23
0

If you just want to highlight the EditText object, you can use PorterDuff instead: http://developer.android.com/reference/android/graphics/PorterDuff.Mode.html.

To set the color:

RegistrationCountry.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);

To remove the color:

RegistrationCountry.getBackground().clearColorFilter();
Gingerade
  • 134
  • 1
  • 3
0

try to set background by :

RegistrationCountry.setBackgroundResource(0);

java acm
  • 1,020
  • 12
  • 24