gpt4 book ai didi

android - 是否可以使用微调器实现公开的下拉菜单

转载 作者:行者123 更新时间:2023-11-29 23:05:10 44 4
gpt4 key购买 nike

Material design 有一个使用 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 的编辑以避免使用自动完成功能,但在选择其中一项后,自动完成功能仅列出与该 View 中使用的筛选器所选择的项目文本相匹配的项目。这是代码:

    <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()
}

所以,我想知道是否可以使用微调器实现它

enter image description here

这是我使用微调器的尝试,但它没有正确显示样式 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>

最佳答案

这就是我一直在寻找的,只需通过覆盖 getFilter 方法来禁用 AutoCompleteTextView 的自动完成功能。 答案张贴在这里 ( AutoCompleteTextView - disable filtering )

关于android - 是否可以使用微调器实现公开的下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56633948/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com