Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android TextInputLayout后缀/前缀_Android_Android Textinputlayout_Material Components_Material Components Android - Fatal编程技术网

Android TextInputLayout后缀/前缀

Android TextInputLayout后缀/前缀,android,android-textinputlayout,material-components,material-components-android,Android,Android Textinputlayout,Material Components,Material Components Android,我想给TextInputLayout添加后缀。 下面是一个例子 有没有标准的解决方案 没有标准的解决方案,我使用textView right to textInputLayout和editText padding来实现 <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" and

我想给TextInputLayout添加后缀。 下面是一个例子


有没有标准的解决方案

没有标准的解决方案,我使用textView right to textInputLayout和editText padding来实现

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

使用材质组件库中提供的属性,您可以使用属性:

  • 应用程序:前缀文本
  • 应用程序:后缀文本
比如:

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

例如:


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

对您没有帮助?没有必要使用AppCompatTextView,因为当您使用TextView时,它会自动膨胀。当我尝试此操作时,提示的浮动标签会显示在示例图像中(“Test”)被移出到前缀的末尾。你知道有什么方法可以避免这种情况,这样它就可以像示例一样工作了吗image@Gober这很奇怪。发布一个包含所有详细信息的问题。在此处发布问题:@Gabriele Mariotithe前缀无疑是可见的,但前缀和文本之间的对齐方式非常不一致:(如何在前缀和文本之间添加填充?