【问题标题】:TextInputLayout: Remove padding between text and suffixTextTextInputLayout:删除文本和后缀文本之间的填充
【发布时间】:2020-11-03 17:14:10
【问题描述】:

我在我的设计中使用TextInputLayout 来显示价格布局。添加了suffixText 用于显示货币符号,该符号必须恰好显示在输入的文本旁边。

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textfield_downpayment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Price Details"
        app:boxBackgroundColor="@android:color/transparent"
        app:hintEnabled="true"
        android:textColorHint="#ffffff"
        app:suffixTextColor="#ffffff"
        app:suffixText="LE">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:inputType="number"
            android:text="1234" />
    </com.google.android.material.textfield.TextInputLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

截至目前,suffixText 显示在末尾,这不是我的预期行为。需要删除textsuffixText之间的明显间隙

尝试将TextInputEditTextlayout_width 更改为wrap_content,这也将提示文本包装在TextInputLayout 中。

【问题讨论】:

  • 你能把整个xml文件贴出来吗?
  • 已更新完整版式

标签: android material-design material-components-android android-textinputlayout android-textinputedittext


【解决方案1】:

您会考虑在数字下方添加货币符号吗?例如,像这样:

如果你喜欢这样,你只需要将 suffixText 行替换为:

app:helperText="LE"
app:helperTextTextColor="@color/black"

【讨论】:

  • 但是它在TextInputEditText下面显示了helperText,我需要在textsuffixText之间的文本删除间隙旁边显示
  • 从我看到的许多示例中,现在可以使用 suffixText 来做到这一点。这是从它的本性到相反的一面。我认为的一种方法是在文本字段中写入货币符号:android:text="1234 LE"。
  • 在文本字段中显示货币符号将使其可编辑,货币符号需要不可编辑
【解决方案2】:

您可以在TextInputEditText中添加android:textAlignment="textEnd"

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Price Details"
    app:suffixText="LE">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:textAlignment="textEnd"
        android:text="1234" />

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多