AutoCompleteTextView float hint

I’ve tried a lot, but can’t make work an AutoCompleteTextView float hint using the TextInputLayout from support.

It’s possible or I need to use an external library?

  • What are the most popular android open source ui libraries
  • ConnectivityManager.EXTRA_NO_CONNECTIVITY is always false on Android Lollipop
  • What is the correct way to get layout inflater in Android?
  • How to control the width and height of the default Alert Dialog in Android?
  • Handling PagerTitleStrip click in compatibiliy Fragment-based ViewPager
  • How to start a new Thread in a service?
  • Related posts:

    How to add APN in Android (KitKat and above) programmatically
    What is GCM Registration ID?
    com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to inst...
    How to delay execution android
    Gujarati Font Rendering
    Android extras about speech recognition does not work
  • What's tools:layout in fragment xml file?
  • Android OpenGL: crazy aspect ratio after sleep
  • How to use @Contract annotation
  • Platform L is a preview and requires application manifest to set minSdkVersion to 'L'
  • Where to put text files in directory in Android
  • Android notify when phone book is updated(Content Observer)
  • 3 Solutions collect form web for “AutoCompleteTextView float hint”

    No .

    design library itself is enough

    include like this

    <android.support.design.widget.TextInputLayout
        android:id="@+id/til_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="125dp"
        >
    
        <AutoCompleteTextView
            android:id="@+id/auto_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Id"
            android:singleLine="true"/>
    </android.support.design.widget.TextInputLayout>
    

    enter image description here

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    

    }

    for more reference click here http://androiddhina.blogspot.in/2015/10/android-material-design-floating-labels-for-edittext.html

    It’s maybe a little bit late but here is the trick:

    Create the following Class,

    public class AutoCompleteTextInputLayout extends TextInputLayout {
    
        private boolean mIsHintSet;
        private CharSequence mHint;
    
        public AutoCompleteTextInputLayout(Context context) {
            super(context);
        }
    
        public AutoCompleteTextInputLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public void addView(View child, int index, ViewGroup.LayoutParams params) {
            if (child instanceof EditText) {
                mHint = ((EditText) child).getHint();
            }
            super.addView(child, index, params);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
    
            if (!mIsHintSet && ViewCompat.isLaidOut(this)) {
                setHint(null);
    
                EditText editText = getEditText();
                if (editText == null) {
                    return;
                }
                CharSequence currentEditTextHint = editText.getHint();
                if (!TextUtils.isEmpty(currentEditTextHint)) {
                    mHint = currentEditTextHint;
                    editText.setHint("");
                }
                setHint(mHint);
                mIsHintSet = true;
            }
        }
    }
    

    Now Add this lines to your layout file and see the magic

    <com.example.AutoCompleteTextInputLayout
        android:id="@+id/text_input_autocomplete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <AutoCompleteTextView
            android:id="@+id/autocomplete_tv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textColorHint="@color/textColorDarkHint"/>
    </com.example.AutoCompleteTextInputLayout>
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.