material-components / material-components/material-components-android

[TextInputLayout] Ability to set background color for helper texts

Open
#1,250 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting Design Feedback feature request Widget: TextField
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
Sometimes error text doesn't fare well with dark backgrounds of the TextInputLayout, like in this image.

grafik

**Describe the solution you'd like**
So it would be nice to have a way to customize the background of the indicator so that we can avoid this issue. Like an `boxBackgroundErrorColor` attribute.

E.g.
grafik

**Describe alternatives you've considered**
I achieved that behavior through a hacky implementation where I findViewById the error text helper and get the parent of it and set the background to the desired color.
```
val emailTextView = binding.emailContainer.findViewById(R.id.textinput_error)

(emailTextView.parent.parent as ViewGroup).setBackgroundColor(Color.parseColor("#FCEEEE"))
```

But as I said it is a hacky and fragile implementation as it would easily break if the implementation details of the Helper Text changes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with TextInputLayout and the textinput_error helper referenced in the issue, including how the helper's parent background is currently reached. Define the supported customization point for the indicator background and verify that the configured color is applied to helper and error text without relying on the internal view hierarchy.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
design, mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.