【问题标题】:Altering TextInputLayout hint behavior更改 TextInputLayout 提示行为
【发布时间】:2018-11-20 08:50:17
【问题描述】:

我需要以这种方式更改 TextInputLayout 行为。默认情况下,当用户单击布局内的 EditText 时,提示会离开文本框并转到上方。我需要实现的是:当用户点击 EditText 时,提示没有反应。它在用户开始输入时移动,然后返回 EditText 为空。

我使用了一个自定义库,其中包含一个名为 FloatingEditText 的东西,但它不能与 RTL 布局一起正常工作。有谁知道如何使用 TextInputLayout 或其他从右到左很好地工作的方式来实现这一点?

提前致谢!

【问题讨论】:

    标签: java android kotlin material-components-android android-textinputlayout


    【解决方案1】:

    您可以在标签部分输入要输入的名称,在印度部分输入提示。

    <android.support.design.widget.TextInputLayout
            android:id="@+id/text_input"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Label">
    
            <EditText
                android:id="@+id/edit_text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="text" />
    
        </android.support.design.widget.TextInputLayout>
    

    【讨论】:

    • 嘿 Ömür,我在 TextInputLayout 中添加了提示,但它根本没有帮助。我也不明白在用户开始输入之前应该如何防止提示出现......
    【解决方案2】:

    通过材质组件库,您可以使用placeholderText 属性:

        <com.google.android.material.textfield.TextInputLayout
            android:hint="Label"
            app:placeholderText="placeholder"
    

    注意:这至少需要 1.2.0 版本。

    【讨论】:

      猜你喜欢
      • 2015-11-19
      • 2020-06-05
      • 2017-03-06
      • 2015-12-26
      • 1970-01-01
      • 2015-08-29
      • 2018-11-03
      • 2015-09-15
      相关资源
      最近更新 更多