material-components / material-components/material-components-android
[MaterialAutoCompleteTextView] Default item layout not available with ExposedDropdownMenu for ArrayAdapters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
When we set the items of MaterialAutoCompleteTextView on the XML with
<com.google.android.material.textfield.MaterialAutoCompleteTextView
app:simpleItems="@array/customer_types"
We can see a color change of the selected item when the dropdown menu is shown.
If we set the items with an ArrayAdapter as
val customerTypes = resources.getStringArray(R.array.customer_types)
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, customerTypes)
arrayAdapter.setAdapter(adapter)
The coloring of the selected item is not working. I've tried many available item layouts and none worked as the default. I looked at the code and I saw these lines
simpleItemLayout =
attributes.getResourceId(
R.styleable.MaterialAutoCompleteTextView_simpleItemLayout,
R.layout.mtrl_auto_complete_simple_item);
As far as I can see this is not available to use.
Describe the solution you'd like
Able to give the layout to an ArrayAdapter so that the selected item can be colored ( there is already XML for the color of the selected simpleItemSelectedColor)
Describe alternatives you've considered
I've tried to create my item layouts, however, I couldn't see any of the state_??? are helpful for the background drawable. Is it possible to write this behavior?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in MaterialAutoCompleteTextView.java around the simpleItemLayout resource lookup and compare the XML simpleItems path with ArrayAdapter usage. Investigate how simpleItemSelectedColor is applied and determine how an ArrayAdapter can receive the default item layout; done means the selected item is colored for ArrayAdapters as it is for simpleItems.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100