question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextInputLayout] Support prefix/suffix text

See original GitHub issue

Is 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. Screen Shot 2019-07-30 at 11 23 05 AM

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 the TextInputEditText. Causes the label to be misaligned when the field is focused, and also overrides the drawable tint color: Screen Shot 2019-07-30 at 11 23 51 AM

  • Setting a TextDrawable as the startIconDrawable on the TextInputLayout. Does not line up with the user’s cursor, padding must be set, and also overrides the drawable tint color: Screen Shot 2019-07-30 at 11 24 30 AM

  • Subclassing TextInputLayout and using a custom CollapsingTextHelper. 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 use TextInputLayout in many places and want a uniform experience.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:21
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

37reactions
leticiarossicommented, Aug 20, 2019

We’ve decided to start working on support for suffix/prefix on text fields

10reactions
devgen90commented, Mar 18, 2020

seeing the alignment issues when using the prefixtext. Has this been addressed already?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TextInputLayout suffix/prefix - android - Stack Overflow
With the TextInputLayout provided in the Material Components Library you can use the attrs: app:prefixText : prefix text; app:suffixText ...
Read more >
Adding a prefix to TextInputEditText | by Rohail Ahmad - Medium
An easier approach would be to extend TextInputEditText which means create your custom PrefixEditText. It does support prefix text changing.
Read more >
TextInputLayout | Android Developers
Also supports: ... Returns the ColorStateList used for the prefix text. ... Returns the suffix text that was set to be displayed with ......
Read more >
Text fields - Material Design
Android's text field component APIs support both label text and helper text for informing the user as to what ... Adding a prefix/suffix...
Read more >
Set unchangeable some part of EditText android
Adding a prefix/suffix to a text field Using text fields programmatically If you construct the TextInputEditText child of a TextInputLayout programmatically ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found