2

I have a edit text field. I want it to have a transparent background. But when the user tries to edit it, it should be with a different background say white color and text color as black. And when he is done with the edit of the edit text and moves to the next control to enter other values i want the background to be transparent again. Please let me know how this is possible in android. Thank you for the help and time.

Vinod
  • 31,933
  • 35
  • 96
  • 119

2 Answers2

3
EditText editText = (EditText)findViewById(R.id.edit1);
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        EditText editText = (EditText)findViewById(R.id.edit1);
        editText.setBackgroundColor(hasFocus ? Color.WHITE : Color.TRANSPARENT);
        editText.setTextColor(hasFocus ? Color.BLACK : Color.GRAY);
    }
});
scessor
  • 15,995
  • 4
  • 43
  • 54
1

implement method onFocusChabgeListener() like below.

textView.setOnFocusChangeListener(new OnFocusChangeListener(){

if(textView.hasFocuss){
//set textColor and background color
}
else
{
//reset it
}

});
ngesh
  • 13,398
  • 4
  • 44
  • 60