The code consists of two parts: the first part is the definition of an extension function setUnderlineColor that can be used to change the underline color of an EditText, and the second part is the implementation of a simple activity that demonstrates how to use the setUnderlineColor function. The setUnderlineColor function takes an integer parameter color that represents the color of the underline. The function first calls the mutate method on the EditText's background drawable. This is necessary because the setColorFilter method modifies the drawable, and we don't want to modify the original drawable that's defined in the XML layout. Next, the function checks the API level using Build.VERSION.SDK_INT . If the API level is greater than or equal to Build.VERSION_CODES.Q (Android 10), then the function sets a BlendModeColorFilter on the background drawable. Otherwise, it sets a PorterDuff color filter. The BlendModeColorFilter and PorterDuff color filter both achi...
Android, .NET C#, Flutter, and Many More Programming tutorials.