[TextInputLayout] Support prefix/suffix text
See original GitHub issueIs your feature request related to a problem? Please describe. Per the “Prefix and suffix text” section at https://material.io/design/components/text-fields.html material text fields should be able to display non-editable text before/after the user’s input.
Describe the solution you’d like I have no strong opinions on the API, but I would consider the minimum-viable functionality to be setting a start-justified prefix text or end-justified suffix text. It would be nice to have the ability to set the start/end gravity of the user’s input text (ex: the “55/100” example in the screenshot above), but I wouldn’t consider it essential. I assume that the hint/label animation would be omitted when prefix/suffix text is provided, otherwise the visibility will need to be coordinated.
Describe alternatives you’ve considered
-
Using a
TextWatcher
and calculating start/end indices manually, as well as setting spans for text color. Ridiculously tedious and error-prone. -
Setting a
TextDrawable
on the left of theTextInputEditText
. Causes the label to be misaligned when the field is focused, and also overrides the drawable tint color: -
Setting a
TextDrawable
as thestartIconDrawable
on theTextInputLayout
. Does not line up with the user’s cursor, padding must be set, and also overrides the drawable tint color: -
Subclassing
TextInputLayout
and using a customCollapsingTextHelper
. Tedious and fragile (uses reflection); see https://stackoverflow.com/a/39568320 -
Using a custom view and ignore
TextInputLayout
entirely. Doable but would like to avoid trying to duplicate the exact styles and positions of views, since we useTextInputLayout
in many places and want a uniform experience.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:21
- Comments:17 (4 by maintainers)
Top GitHub Comments
We’ve decided to start working on support for suffix/prefix on text fields
seeing the alignment issues when using the prefixtext. Has this been addressed already?