Removing the background color of an EditText

前端 未结 3 1791
一个人的身影
一个人的身影 2020-12-19 17:41

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

 RegistrationCountry.setBackgroundColor(Color.RED);

Now i yould

相关标签:
3条回答
  • 2020-12-19 18:11

    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.

    0 讨论(0)
  • 2020-12-19 18:11

    try to set background by :

    RegistrationCountry.setBackgroundResource(0);

    0 讨论(0)
  • 2020-12-19 18:15

    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();
    
    0 讨论(0)
提交回复
热议问题