Android AutoCompleteTextView浮点提示
我已经尝试了很多,但是无法使用来自support的Android AutoCompleteTextView浮点提示,android,material-design,android-support-library,autocompletetextview,android-textinputlayout,Android,Material Design,Android Support Library,Autocompletetextview,Android Textinputlayout,我已经尝试了很多,但是无法使用来自support的TextInputLayout使工作成为AutoCompleteTextViewfloat提示 有可能,或者我需要使用外部库?否 设计库本身就足够了 像这样包括 <android.support.design.widget.TextInputLayout android:id="@+id/til_id" android:layout_width="match_parent" a
TextInputLayout
使工作成为AutoCompleteTextView
float提示
有可能,或者我需要使用外部库?否
设计库本身就足够了
像这样包括
<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>
可能有点晚了,但关键在于: 创建以下类
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;
}
}
}
现在,将这些行添加到布局文件中,并查看神奇之处
<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>
您完全可以使用设计库来完成。发布你的代码,以便我能更好地帮助你。请解释“不能工作”的含义。换句话说,你需要向我们提供你的问题的详细信息。谢谢,我有一个特殊的布局不起作用,我正在试图找出我的错误。你想在那个链接上显示什么?完全没用。你真的能把它指向代码中的特定类或行吗?@delkant有答案代码,但随着时间的推移,repo被更新了。谢谢你的指点谢谢你的澄清!2020年,这仍然有效。尽管我想指出的是,这会有一个小的设计问题,因为textinputtext
添加了一个填充,而AutoCompleteTextView
没有。因此,在AutoCompleteTextView
中添加一个paddingandroid:padding=“16dp”
将使其看起来与以前完全相似