TextInputLayout后缀/前缀

neg*_*ffx 10 android android-textinputlayout material-components material-components-android

我想在TextInputLayout中添加后缀。一个例子取自material.io

例

有没有标准的解决方案?

Gab*_*tti 7

使用TextInputLayout材料组件库中提供的,您可以使用attrs:

  • app:prefixText:前缀文本
  • app:suffixText:后缀文字

就像是:

<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>
Run Code Online (Sandbox Code Playgroud)

例:

在此处输入图片说明

注意:这要求最低版本为1.2.0-alpha01


Ove*_*vel 5

没有标准的解决方案,我使用textView来实现textInputLayout和editText填充。

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:gravity="bottom">

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Hint"
                app:errorEnabled="true">

                <android.support.v7.widget.AppCompatEditText
                    style="@style/RegistrationEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingRight="80dp" />
            </android.support.design.widget.TextInputLayout>

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerInParent="true"
                android:paddingBottom="12dp"
                android:paddingRight="8dp"
                android:text="rightLabel" />
        </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)