-1

I have an EditText that looks like this:

default editText

When doing an action in the EditText the background is changed with the following code:

edtCampo.setBackgroundColor(Color.RED);

editText with background

Then another action is made and the EditText background is changed again with the following code:

edtCampo.setBackgroundColor(Color.TRANSPARENT);

editText with transparent background

The problem is that in the EditText I do not see the line below, what property should I give to make it look like the first image ?

Firoz Memon
  • 3,027
  • 2
  • 17
  • 28

2 Answers2

0

Try to use

int backgroundResource = 0;
if(redBackgroundNeeded){
    backgroundResource = R.color.red;
}
view.setBackgroundResource(backgroundResource);
Andrey Busik
  • 381
  • 2
  • 14
0

Try to use,

android:backgroundTint="@color/red"

To achieve pro-grammatically,

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    edt1.setBackgroundTintList(getResources().getColorStateList(R.color.red));
}

Result,

enter image description here

Dhruv
  • 1,459
  • 1
  • 18
  • 25