Search code examples
androidandroid-textinputlayoutmaterial-componentsmaterial-components-android

TextInputLayout suffix/prefix


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

Example

Are there any standard solutions?


Solution

  • 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.