Search code examples
androidandroid-edittextandroid-api-levels

How to color the EditText focus color for API < 21?


I have EditTexts and they color the bottom line in primary color as you can see here

I want to leave it black, so I set in my layout for the EditText:

android:backgroundTint="@android:color/black"

This works nice, but I have minSDK set to 19. So I immediately get a warning that this would not work for API < 21

How can I solve this for API 19 and API 20 as well?


Solution

  • I used a code like this, and it works for me:

    yourEditText.getBackground().setColorFilter(getResources().getColor(android.R.color.black), PorterDuff.Mode.SRC_IN);

    I hope it works to you