use*_*321 4 android material-design mdc-components
我一直在寻找Material design Material.io中的材料组件,一切都很好,我试图使用MDC的TextField组件创建一个材料下拉式微调器,但是我似乎找不到任何相关文档,是否有可能使用MDC创建微调器?如果是这样,我在哪里可以找到它的文档?
在那里看到TextField目录中的微调框,我可以这样做吗?:
在Material Design网站上,其标记为“针对Android计划”(Material Menus),我还注意到Material Design的Twitter feed刚刚针对Web发布。因此,希望不久后将发布一个实际的实现。
这正是您需要的
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>
Run Code Online (Sandbox Code Playgroud)
然后,您可以设计菜单项,如下所示:
<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"/>
Run Code Online (Sandbox Code Playgroud)
用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);
Run Code Online (Sandbox Code Playgroud)
您可以更改样式以满足各种变化,例如:Filled style =“ @ style / Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu”`
概述将这种样式应用于您的TextInputLayout:
style =“ @ style / Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu”`密集填充将此样式应用于您的TextInputLayout:
style =“ @ style / Widget.MaterialComponents.TextInputLayout.FilledBox.Dense.ExposedDropdownMenu”`Dense Outlined将此样式应用于您的TextInputLayout:
style =“ @ style / Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu”`
归档时间: |
|
查看次数: |
2379 次 |
最近记录: |