代码之家  ›  专栏  ›  技术社区  ›  thelastchief

物料组件文本字段-如何设置前缀和后缀?[副本]

  •  0
  • thelastchief  · 技术社区  · 7 年前

    一个例子来自 material.io

    Example

    有什么标准的解决方案吗?

    0 回复  |  直到 6 年前
        1
  •  6
  •   VipiN Negi    8 年前

    没有标准的解决方案,我是用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>
    
        2
  •  7
  •   Mark Reid Stark    6 年前

    与 TextInputLayout 在材质组件库中提供,可以使用属性:

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

    enter image description here

    注: 这需要最低版本 1.2.0-字母01 .