【发布时间】:2021-06-28 06:23:45
【问题描述】:
我在material-text-field 中阅读了文档,并且在 editText 上有 auto-complete-textView 作为提示而不是下拉菜单。你可以看到下面的图片。但我做不到。我尝试了一些带有 textinputlayout 和 material-auto-complete-text 的代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til"
..>
<com.google.android.material.textfield.MaterialAutoCompleteTextView
.../>
</com.google.android.material.textfield.TextInputLayout>
在片段中
ArrayList<String> items = new ArrayList<>();
items.add("Material");
items.add("Design");
items.add("Components");
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,R.layout.item, items);
TextInputLayout textInputLayout = findViewById(R.id.til);
并设置适配器
((MaterialAutoCompleteTextView) textInputLayout.getEditText()).setAdapter(adapter);
((MaterialAutoCompleteTextView) textInputLayout.getEditText()).setText(adapter.getItem(1),false);
但是 auto-complete-textview 提示下拉菜单中的项目而不是 editText 作为提示。
我想要AutoC完整,因为“AutoC”必须是文本,“完整”必须是提示
我该怎么做??
【问题讨论】:
-
这是材料组件库中的正常行为
标签: android kotlin autocompletetextview material-components-android