Keep TextInputLayout always focused or keep label always expanded

textinputlayout disable label
keep textinputlayout hint always top
textinputlayout error background color
textinputlayout error icon
android support-design widget textinputlayout not found
how to change the floating label color of textinputlayout
android textinputlayout clear button
com.google.android.material.textfield.textinputlayout not working

I was wondering if it's possible to always keep the label expanded regardless of whether or not there is text in the EditText. I looked around in the source and it is a using a ValueAnimator and a counter inside a TextWatcher to animate or not animate changes. Maybe I can set a custom TextWatcher with a custom ValueAnimator on the EditText inside the TextInputLayout?


The current version of the TextInputLayout exists specifically to do one thing - show / hide the helper label depending on whether there's some text in the EditText or not. What you want is different behaviour, so you need a different widget than the TextInputLayout. This case is the perfect candidate to writing a custom view that will suit your needs.

That said, your idea of setting a custom TextWatcher to the EditText won't work either because TextInputLayout doesn't expose anything of it's internals that actually handle the animations - neither updateLabelVisibility(), setEditText(), the magic Handler that does the work or anything else. Of course we surely don't want to go the reflection path for a detail like this, so...

Just use MaterialEditText! It has the following property that does exactly what you want.

met_floatingLabelAlwaysShown: Always show the floating label, instead of animating it in/out. False as default.

The library is quite stable (I'm using it in two different projects myself) and has plenty of options to customise. Hope it helps!

[TextInputLayout] Allow hint to float always · Issue #810 · material , I was wondering if it's possible to always keep the label expanded regardless of whether or not there is text in the EditText. I looked around in the source and it is​  As a result, calls to getParent() on children of the TextInputLayout -- such as a TextInputEditText -- may not return the TextInputLayout itself, but rather an intermediate View. If you need to access a View directly, set an android:id and use findViewById(int) .


For me with support design 23.3.0 it works to use

              <android.support.design.widget.TextInputLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="wow such hint"
              app:hintEnabled="true"
              app:hintAnimationEnabled="false"
              />

Android TextInputLayout Example, Currently it is impossible to set a hint to both TextInputLayout and the labels do not overlapse, but without a focus only hint is showed. Aren't  Android TextInputLayout. Android TexInputLayout extends LinearLayout. The primary use of a TextInputLayout is to act as a wrapper for EditText(or its descendant) and enable floating hint animations.


Despite the top answer, I still simply came up with a Java Reflection solution to achieve the desired behavior (using com.google.android.material.textfield.TextInputLayout from com.google.android.material:material:1.0.0):

/**
 * Creation Date: 3/20/19
 *
 * @author www.flx-apps.com
 */
public class CollapsedHintTextInputLayout extends TextInputLayout {
    Method collapseHintMethod;

    public CollapsedHintTextInputLayout(Context context) {
        super(context);
        init();
    }

    public CollapsedHintTextInputLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CollapsedHintTextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    void init() {
        setHintAnimationEnabled(false);

        try {
            collapseHintMethod = TextInputLayout.class.getDeclaredMethod("collapseHint", boolean.class);
            collapseHintMethod.setAccessible(true);
        }
        catch (Exception ignored) {
            ignored.printStackTrace();
        }
    }

    @Override
    public void invalidate() {
        super.invalidate();
        try {
            collapseHintMethod.invoke(this, false);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Java Reflection is of course never pretty, but in my case, it just was the more handy solution than creating a similar looking widget, and the linked library seemed outdated and abandoned… :/

Don't forget to add the respective ProGuard rules if you use it:

-keepclassmembers class com.google.android.material.textfield.TextInputLayout {
    private void collapseHint;
}

TextInputLayout / Floating Labels In EditText With Example In , I was wondering if it's possible to always keep the label expanded regardless of whether or not there is text in the EditText . I looked around in the source and it is​  If the edit text has focus, the hint moves up, so you can type. because it has to be done via a textAppearance on the TextInputLayout, Keep asking Google for solutions, maybe one day the


Here's a trick you can use that will allow you to put the label hint in the layout and the textbox hint in the edittext without them clashing. It will work better than the above reflection solution as well, as it prevents the original bad drawing from happening and doesn't require you to address minification/proguar settings, since it does class-to-class comparison.

Subclass TextInputEditText as follows:

import android.content.Context
import android.text.Editable
import android.text.SpannableStringBuilder
import android.util.AttributeSet
import com.google.android.material.R
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout

class MonkeyedTextInputEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.editTextStyle) : TextInputEditText(context, attrs, defStyleAttr) {
    @Override
    override fun getText(): Editable? {
        val text = super.getText()
        if (!text.isNullOrEmpty())
            return text
        /* We want this expression in TextInputLayout.java to be true if there's a hint set:
         *        final boolean hasText = editText != null && !TextUtils.isEmpty(editText.getText());
         * But for everyone else it should return the real value, so we check the caller.
         */
        if (!hint.isNullOrEmpty() && Thread.currentThread().stackTrace[3].className == TextInputLayout::class.qualifiedName)
            return SpannableStringBuilder(hint)
        return text
    }
}

Then your layouts can look like:

<com.google.android.material.textfield.TextInputLayout
    ...
    android:hint="YOUR LABEL TEXT"
    ...
    >

    <yourapp.MonkeyedTextInputEditText
        ...
        android:hint="YOUR PLACEHOLDER TEXT"
        ...
        />
</com.google.android.material.textfield.TextInputLayout>

Styling TextInputLayout and TextInputEditText on Android, Android TextInputLayout Example, Android Text Input Layout, android floating hints, android error label animation, character count, password view toggle. Floating Hints are enabled by default in a TextInputLayout. It's noteworthy to mention that the second EditText field doesn't animate the floating hint when focused. Note:When using the password toggle functionality, the 'end' compound drawable of the EditText will be overridden while the toggle is enabled. To ensure that any existing drawables are restored correctly, you should set those compound drawables relatively (start/end), opposed to absolutely (left/right).


TextInputLayout, To display floating label in EditText, TextInputLayout needs to wrapped the Below we set Sans – Serif typeface to use for the expanded and floating hint. Set the hint to be displayed in the floating label, if enabled. void: setHintAnimationEnabled(boolean enabled) Set whether any hint state changes, due to being focused or non-empty text, are animated. void: setHintEnabled(boolean enabled) Sets whether the floating label functionality is enabled or not in this layout. void


Android Design Support Library: TextInputLayout, If the edit text has focus, the hint moves up, so you can type. The Line is also red, because it uses the material Primary Color by default. Keep asking Google for solutions, maybe one day the Keyboard will be easy to show  I have an add-in for Outlook 2016 that I use. This add-in occasionally causes Outlook to startup slowly and Outlook disables it. I want to make it so that this add-in is always enabled regardless of how it affects Outlook. Just to be clear this add-in is being set as disabled, not inactive.


design/src/android/support/design/widget/TextInputLayout.java , Default for the TextInputLayout. Returns the hint which is displayed in the floating label, if enabled. ColorStateList Returns whether any hint state changes, due to being focused or non-empty text, are animated. boolean Sets the text color used by the hint in both the collapsed and expanded states. Every text field should have a label. Label text should be aligned with the input line, and always visible. It can be placed in the middle of a text field, or rest near the top of the container. Do Label text should always be visible, moving from the middle of the text field to the top (if the field is selected).