Have a TextInputLayout only showing a hint after entering the first character

Before, in front of the support library, to have a floating label, I use the following third-party library from Chris Banes.

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

I really like the library. Like, it shows a floating hint only after entering the 1st character.

Before entering, with focus

enter image description here

After input with focus

enter image description here

The code is used here.

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

I decided to go to the Google Design Support Library for better support.

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

However, a floating-point hint will be shown immediately after you press EditText, even before entering the first character.

enter image description here

I was wondering if there is a way to show a floating tooltip only if in EditText?

is there at least 1 input character?
+4
1

, TextWatcher .

0

Source: https://habr.com/ru/post/1614951/


All Articles