1

I would like to change the editTexts line color grammatically if its focused.

I already tried to use a colorStateList

int[][] states = new int[][]{
                new int[]{android.R.attr.state_focused},   
                new int[]{android.R.attr.state_active },    
                new int[]{ -android.R.attr.state_enabled},   
                new int[]{android.R.attr.state_enabled},   
        };

        int[] colors = new int[]{
                highlightColor,
                defaultColor,
                defaultColor,
                defaultColor
        };

        ColorStateList myList = new ColorStateList(states, colors);
        editText.setBackgroundTintList(myList);

I am able to change the normal color of line but the focused is always the default color for editTexts in app.

with this the default is grey, focused is default from app lets say green but I want a lets say red in focused

answers in the proposed thread are XML based, I have to set it dynamicly, also ONLY the highlight/focused color is different, the normal color stays grey

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alex
  • 327
  • 3
  • 11
  • Possible duplicate of [Changing EditText bottom line color with appcompat v7](https://stackoverflow.com/questions/26574328/changing-edittext-bottom-line-color-with-appcompat-v7) – mbo Jul 24 '17 at 14:19

1 Answers1

1

Create a custom EditText and add this.setBackgroundTintList( ColorStateList.valueOf( color ) ); into constructor.

Vlado Pandžić
  • 4,879
  • 8
  • 44
  • 75