TextInputLayout suffix/prefix

negatiffx picture negatiffx · Apr 6, 2017 · Viewed 9.5k times · Source

I want to add suffix to TextInputLayout. An example is taken from the material.io

Example

Are there any standard solutions?

Answer

Gabriele Mariotti picture Gabriele Mariotti · Oct 22, 2019

With the TextInputLayout provided in the Material Components Library you can use the attrs:

  • app:prefixText: prefix text
  • app:suffixText: suffix text

Something like:

<com.google.android.material.textfield.TextInputLayout
    android:hint="Test"
    app:prefixText="@string/..."
    app:prefixTextColor="@color/secondaryDarkColor"
    app:suffixText="@string/..."
    app:suffixTextColor="@color/primaryLightColor"
    ...>

    <com.google.android.material.textfield.TextInputEditText
        .../>

</com.google.android.material.textfield.TextInputLayout>

Example:

enter image description here

Note: This requires a minimum of version 1.2.0-alpha01.