TextInputLayout Disable Floating Hint – This may seem counterintuitive, but is there a way to disable or remove the floating caption tooltip in TextInputLayout?
The reason I want to use TextInputLayout instead of a simple EditText is the counter that TextInputLayout offers.
TextInputLayout Disable Floating Hint
What is TextInputLayout?
TextInputLayout is a layout widget that is part of the Android Design Support Library. It is used to display an EditText field in a floating label style, which means that the hint text associated with the EditText field appears as a floating label above the EditText field when the field is not focused. When the field is focused, the hint text disappears and the user can enter text.
TextInputLayout also provides other useful features, such as error messages, character counting, and a password visibility toggle. It is a convenient way to improve the user experience of an EditText field and make it easier for users to enter and edit text in your Android app.
How to Disable Floating Hint TextInputLayout?
To disable the floating hint in a TextInputLayout, you can set the “hintEnabled” attribute to “false” in the XML layout file or programmatically in your code.
Here’s an example of how to disable the floating hint in an XML layout file:
<android.support.design.widget.TextInputLayout
android:id=”@+id/text_input_layout”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
app:hintEnabled=”false”>
<EditText
android:id=”@+id/edit_text”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:hint=”@string/hint_text”/>
</android.support.design.widget.TextInputLayout>
In the example above, the floating hint is disabled for the TextInputLayout by setting the “hintEnabled” attribute to “false”. The hint text will still be displayed in the EditText field, but it will not float above the field when the field is not focused.
To disable the floating hint programmatically in your code, you can use the setHintEnabled() method of the TextInputLayout object. Here’s an example:
TextInputLayout textInputLayout = findViewById(R.id.text_input_layout);
textInputLayout.setHintEnabled(false);
In the example above, the floating hint is disabled for the TextInputLayout by calling the setHintEnabled() method and passing in “false” as the argument. The hint text will still be displayed in the EditText field, but it will not float above the field when the field is not focused.
Fix TextInputLayout Disable Floating Hint
Solution 1:
As of version 23.2.0 of the support library, you can setHintEnabled (fake) or define it as such in the XML TextInputLayout : app:hintEnabled=false Although the name suggests that this removes all clues, only the hover is removed.
- Related documents and questions: http://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#setHintEnabled (boolean).
- https://code.google.com/p/android/issues/detail?id=181590
Solution 2:
There are three ways to do this: 1 Set android:hint in TextInputLayout to the _ space, and keep android:hint=This is my great set of tips in EditText.
This works because TextInputLayout performs the following check before using the EditText index:
- // If we don’t have a valid index, try taking it out of EditText
as (TextUtils.isEmpty(mHint)) {
setHint(mEditText.getHint());
// delete the EditText index, because we will display it ourselves
mEditText.setHint(null);
}
By setting android:hint=, if (TextUtils.isEmpty(mHint)) evaluates to false, and EditText retains its index. 2 The second option would be to subclassify TextInputLayout and replace the addView method (View child, int index, ViewGroup.LayoutParams params) :
- the public class CTextInputLayout expands the class TextInputLayout {
- public CTextInputLayout(Context) {
this(context, zero);
} - public CTextInputLayout(Context, AttributeSet attrs) {
this(context, attrs, 0);
} - public CTextInputLayout(Context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
} - @Overridepublic void addView(View child, int index, ViewGroup.LayoutParams params) {as (EditText child instance) {/ hides current indexCharSequence hint = ((EditText)child).getHint();// removes the index for now – we don’t want the TextInputLayout to see the((EditText)child).setHint(null);// let `TextInputLayout` doensuper.addView(child, index, params);// finally reset the index((EditText)child).setHint(hint);} other {// continue adding the viewsuper.addView(child, index, parameter);}}}}.
Then use your own CTextInoutLayout instead of the Design Support Library :
3 The third and perhaps easiest way would be to make the following calls:
// remove index from `TextInputLayout`
((TextInputLayout)findViewById(R.id.textContainer)).setHint(null);
// return index to `EditText`
// pass `String` can also be a
string source ((EditText)findViewById(R.id.myEditText)).setHint(This is my class index;)
Solution 3:
With com.google.android.material, you can hide
Solution 4:
I’ve tried all the answers, but they don’t all work now (especially for com.google.android.material:material:1.1.0-beta01). Even if we make changes to the logic of adding EditText to the TextInputLayout, we have an empty area above the field that blocks half of the text and the tooltip. I now have a solution to the problem. The most important thing is the filling in EditText, as mentioned in material.io:
This allows us to set a SearchView type view with a search icon and a delete text button, without all the magic of custom views.
Solution No 5:
If you use the app:hintEnabled=false, you also set android:paddingTop=8dp in EditText and the space for top hints disappear, it worked for me, and I hope it works for you too.
Solution No 6:
myEditText.setOnFocusChangeListener { _, hasFocus ->
as (hasFocus) textContainer.hint = null
else myEditText.hint = getString(R.string.your_string)
}
This makes your hint in text input layout perfect, because if you want to make it disappear with the app:hintEnabled=false, it doesn’t make your text input layout cool.
Solution No 7:
To apply a style to your EditText, add the following code to the file Styles.xml …
For the background effect, create edittext_background.xml in the rendered form.
Solution No 8:
If someone has a problem like me:
The sticker doesn’t fill in the text correctly, so do it:
Adding padding to the top and bottom of TextInputEditText solves the problem.
Solution No 9:
The answer of @Gauthier is correct, but if you want not only a floating hint but also a hint for editing text, you have to enter a hint in the EditText widget next to disable the hint for TextInputLayout.
I think this is an answer to some of the questions asked by some people in the comments above.
Solution No 10:
I think this will help you:
text container.setHintAnimationEnabled(false) ;
Also Check: Best Phone for Rooting
Good luck! hope you can fix the TextInputLayout Disable Floating Hint issue easily now.