AutoCompleteTextView浮动提示

我已经尝试了很多,但无法使用支持的TextInputLayout使AutoCompleteTextView浮点提示工作。

有可能或者我需要使用外部库吗?

不。

设计库本身就足够了

包括这样的

    

在此处输入图像描述

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

}

如需更多参考,请点击此处http://androiddhina.blogspot.in/2015/10/android-material-design-floating-labels-for-edittext.html

这可能有点晚了但是这就是诀窍:

创建以下类,

 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; } } } 

现在将这些行添加到您的布局文件中并查看魔法