Would be possible have my hint text always top, as if it were focusable?
I tried this:
<android.support.design.widget.TextInputLayout
android:id="@+id/etSurnameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/llNameImage"
android:hint="My Hint Text"
app:hintEnabled="true"
app:hintAnimationEnabled="false"
android:textColorHint="@color/gray_title">
Floating Hints are enabled by default in a TextInputLayout. To disable it we need to add the following attribute inside the tag : app:hintEnabled="false" . The below xml code is from the activity_main. xml layout and has three EditText fields.
TextInputLayout textInputCustomEndIcon = findViewById(R. id. editText); final TextInputEditText editText = new TextInputEditText(textInputCustomEndIcon. getContext()); textInputCustomEndIcon.
Actually, from com.google.android.material:material:1.3.0-alpha03
or higher, you can simply set app:expandedHintEnabled="false"
to make it always float.
Here's a hack - programmatically add a space in the text if it's empty. However, you would then have to remove the space if it's focused, else the user will start typing with a leading whitespace. Another option is to always trim
the text typed by user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With