首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复TextInputLayout中的“文本提示”?

如何修复TextInputLayout中的“文本提示”?
EN

Stack Overflow用户
提问于 2019-03-25 17:36:44
回答 1查看 862关注 0票数 1

我需要在TextInputLayout中使用"errorValidation“和"hint”。我想修复TextInputLayout中的提示,即它不会转到我的TextInputLayout的标签上。实际上,我希望这个提示首先是一个标签。

换句话说:我使用提示作为TextInputLayout的标签的TextView,但问题是空白太多!我该怎么处理呢?

附件中的图片定义了如何使用TextView作为TextInputLayout的标签。

我使用的代码如下:

代码语言:javascript
复制
<androidx.appcompat.widget.AppCompatTextView
    android:id="@+id/tv_label_previous_password"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@id/toolbar_change_password"
    android:layout_marginTop="@dimen/spacing_5x"
    android:layout_marginStart="@dimen/spacing_3x"
    android:text="@string/label_previous_password"
    style="@style/TextHintYekanRegularHintColor16" />

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/til_previous_password"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@id/tv_label_previous_password"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:layout_marginStart="@dimen/spacing_3x"
    android:layout_marginEnd="@dimen/spacing_3x"
    style="@style/TextInputLayoutAppearance" >

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/et_previous_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/TextYekanRegularColorPurpleOne16"
        android:inputType="textPassword" />

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-28 14:28:05

您可以使用两个技巧来解决TextInputLayout的边际问题。您已经使用了一个使用普通EditText而不是提示的技巧。然后您必须设置

代码语言:javascript
复制
app:hintEnabled="false"

若要删除TextInputLayout顶部的页边距,请执行以下操作。

第二个技巧是,您应该在片段或活动而不是布局文件中为TextInputLayout启用错误。这将删除TextInputLayout底部的页边距。当error消失后,您应该为TextInputLayout禁用error。下面的代码将为您完成以下工作:

代码语言:javascript
复制
your_text_input_layout.isErrorEnabled = true // to enable the error
your_text_input_layout.isErrorEnabled = false // to disable the error
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55334847

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档