Material design 有一个 Exposed Dropdown Menu,实现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>
Run Code Online (Sandbox Code Playgroud)
但是我需要具有相同的外观和感觉,但具有微调器行为(没有自动完成功能,只需显示弹出窗口并选择一个项目)。
我禁用了对 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"**/>
Run Code Online (Sandbox Code Playgroud)
当点击它时,我还放了一个监听器来打开项目列表
val editTextFilledExposedDropdown = findViewById<AutoCompleteTextView>(R.id.filled_exposed_dropdown)
editTextFilledExposedDropdown.setAdapter(adapter)
editTextFilledExposedDropdown.setOnClickListener {
(it as AutoCompleteTextView).showDropDown()
}
Run Code Online (Sandbox Code Playgroud)
所以,我想知道是否可以使用微调器来实现这一点
这是我使用微调器的尝试,但它没有正确显示样式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>
Run Code Online (Sandbox Code Playgroud)