我正在研究材质组件的材质设计Material.io,一切都很好,我试图使用MDC的TextField组件来创建材质下拉式微调器,但我似乎找不到任何相关文档,是否可以使用MDC创建微调器?如果是这样,我在哪里可以找到它的文档?
在TextField的目录中看到了一个旋转器,我可以这样做吗?:

发布于 2018-12-18 15:39:08
在Material Design网站上,它被标记为安卓计划(Material Menus),我还注意到Material Design的Twitter feed,它刚刚在网络上发布。因此,希望很快就能发布一个实际的实现。
发布于 2019-05-21 21:09:07
这正是您需要的
https://material.io/develop/android/components/menu/#exposed-dropdown-menus
首先在Textinputlayout中添加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>然后您可以像这样设计菜单项:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceSubtitle1"/>在java中初始化adadpter,如下所示:
String[] COUNTRIES = new String[] {"Item 1", "Item 2", "Item 3", "Item 4"};
ArrayAdapter<String> adapter =
new ArrayAdapter<>(
getContext(),
R.layout.dropdown_menu_popup_item,
COUNTRIES);
AutoCompleteTextView editTextFilledExposedDropdown =
view.findViewById(R.id.filled_exposed_dropdown);
editTextFilledExposedDropdown.setAdapter(adapter);您可以更改样式以满足各种变化,例如:
已填充的style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
概述
将此样式应用于您的TextInputLayout:
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
密集填充
将此样式应用于您的TextInputLayout:
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense.ExposedDropdownMenu"
密集轮廓
将此样式应用于您的TextInputLayout:
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
https://stackoverflow.com/questions/53022001
复制相似问题