【发布时间】:2019-10-31 04:52:23
【问题描述】:
Material 设计有一个使用 AutoCompleteTextView 实现的公开下拉菜单,如下所示:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_text">
<AutoCompleteTextView
android:id="@+id/filled_exposed_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
但我需要具有相同的外观和感觉,但具有微调器行为(没有自动完成,只需显示弹出窗口并选择一个项目)。
我禁用了 AutoCompleteTextView 上的编辑以避免使用自动完成功能,但是在选择其中一项后,自动完成功能只会列出与所选项目文本匹配的项目,给定此视图中使用的过滤器。这是代码:
<AutoCompleteTextView
android:id="@+id/filled_exposed_dropdown"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
**android:editable="false"**/>
我还设置了一个监听器,以便在单击时打开项目列表
val editTextFilledExposedDropdown = findViewById<AutoCompleteTextView>(R.id.filled_exposed_dropdown)
editTextFilledExposedDropdown.setAdapter(adapter)
editTextFilledExposedDropdown.setOnClickListener {
(it as AutoCompleteTextView).showDropDown()
}
所以,我想知道是否可以使用微调器来实现这一点
这是我使用微调器的尝试,但它无法正确显示样式OutlinedBox.Dense.ExposedDropdownMenu,并且还显示了两个箭头底部图标,我认为一个用于样式,另一个用于微调器。
这是带有微调器的代码:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hint">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/layout_id"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Currency">
<androidx.appcompat.widget.AppCompatSpinner
android:id="@+id/my_spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</com.google.android.material.textfield.TextInputLayout>
【问题讨论】:
标签: android material-design android-view autocompletetextview