Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep Textinputlayout hint always top

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">
like image 353
Aris Guimerá Avatar asked Nov 29 '16 12:11

Aris Guimerá


People also ask

How do I turn off hint in TextInputLayout?

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.

How do I get TextInputLayout from text?

TextInputLayout textInputCustomEndIcon = findViewById(R. id. editText); final TextInputEditText editText = new TextInputEditText(textInputCustomEndIcon. getContext()); textInputCustomEndIcon.


2 Answers

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.

like image 94
Dimas Mendes Avatar answered Oct 22 '22 08:10

Dimas Mendes


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.

like image 27
Aba Avatar answered Oct 22 '22 08:10

Aba