Android – lets textinputlayout display a prompt only after the first character is typed
Previously, to use floating tags before supporting libraries, I used the following third-party libraries from Chris banes
https://gist.github.com/chrisbanes/11247418
The library is perfect for me because the floating prompt is displayed only after the first character is entered
Before typing, there is focus
After typing, there is focus
This is the code used
<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 migrate to 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, after you follow EditText, the floating prompt is displayed immediately even before you type the first character
I wonder if there is any way to display the floating prompt. There is at least one input character in EditText?
resolvent:
You may want to implement textwatcher and manually set the focus to the desired text length