【问题标题】:Have TextInputLayout only showing hint after typing the first character让 TextInputLayout 仅在输入第一个字符后显示提示
【发布时间】:2016-02-09 07:49:36
【问题描述】:

以前,在支持库之前,为了有浮动标签,我使用的是 Chris Banes 的以下 3rd 方库。

https://gist.github.com/chrisbanes/11247418

图书馆很适合我。因为,它仅在输入第一个字符后才会显示浮动提示。

打字前,重点突出

打字后,重点突出

这是正在使用的代码。

<org.yccheok.portfolio.FloatLabelLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    app:floatLabelTextAppearance="@style/PortfolioFloatLabel">
    <EditText
        android:id="@+id/unit_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/new_buy_portfolio_unit"
        android:singleLine="true"
        android:inputType="numberDecimal"
        android:imeOptions="actionNext|flagNoExtractUi">
        <requestFocus />
    </EditText>
</org.yccheok.portfolio.FloatLabelLayout>

我决定迁移到 Google 设计支持库以获得更好的支持。

<android.support.design.widget.TextInputLayout
    android:id="@+id/usernameWrapper"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp">
    <EditText
        android:id="@+id/unit_edit_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/new_buy_portfolio_unit"
        android:singleLine="true"
        android:inputType="numberDecimal"
        android:imeOptions="actionNext|flagNoExtractUi">
        <requestFocus />
    </EditText>
</android.support.design.widget.TextInputLayout>

但是,浮动提示会立即显示,就在您关注 EditText 之后,甚至在输入第一个字符之前。

我想知道,有没有办法显示浮动提示,仅当EditText 处至少有 1 个输入字符时?

【问题讨论】:

  • 我也面临同样的问题

标签: android


【解决方案1】:

您可能希望实现一个 TextWatcher 并将焦点手动设置为所需的文本长度。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 2016-06-06
    • 2012-08-17
    相关资源
    最近更新 更多