Closed juvs closed 1 year ago
I think it's WAI. Your spinner is wider than the text field. If you don't want your menu item to be ellipsized, please make the text input layout wider so the drop down menu can contain all the characters.
@drchen Thanks, but in my sample app, both the Spinner and TextInputLayout + AutoCompleteTextView have the same height, "wrap_content", and if you select a value int both they show the value correctly, the problem is on the dropDown items.
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/regimenFiscalTIL"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:hint="Test 1">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
<Spinner
android:id="@+id/regimenFiscal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp" />
TextInputLayout has its own paddings. So the actual measured width of AutoCompleteTextView will be narrower than the Spinner I believe. (it can also be seen in your previous screenshots.)
@drchen Sorry to insist, the problem is not the width of both components (Spinner/AutoCompleteTextView) the problem is the way AutoCompleteTextView render the dropdown list, as you can see the item layout have the necessary to wrap text in each item on the dropDown.
Not wrapping text, this text is almost 2 lines
This dropDown is from the Spinner, it's intent just has an example in order to rest my case that AutoCompleteTextView is not wraping.
Both ArrayAdaters have the same item layout
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tool="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:padding="16dp"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
tool:text="Este es un texto de prueba largo en multiples líneas para probar el texti \nCon un salto de línea como prueba adicional" />
Please, take a look an my attached sample app.
Oh ok. I see, so you want your drop down items to be multi-line. Let me check if there's an easy way for you to do that.
Hi so MaterialAutoCompleteTextView
will use ?attr/simpleItemLayout
to render its autocomplete item. By default it specifies android:maxLines="1"
.
To override that settings you need to (it's a little bit complicated, I apologize for that):
android:singleLine="false"
.<style name="CustomAutoCompleteStyle" parent="Widget.Material3.AutoCompleteTextView.OutlinedBox">
<item name="simpleItemLayout">@layout/m3_auto_complete_simple_item</item>
</style>
<style name="ThemeOverlay.CustomAutoCompleteTextView">
<item name="autoCompleteTextViewStyle">@style/CustomAutoCompleteStyle</item>
</style>
<style name="CustomExposedDropdownMenu" parent="Widget.Material3.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
<item name="materialThemeOverlay">@style/ThemeOverlay.CustomAutoCompleteTextView</item>
</style>
TextInputLayout
Hope this helps! : )
Or you can just set app:simpleItemLayout="...your custom layout"
on the AutoCompleteTextView in your text field layout file, btw. : )
Description: Using com.google.android.material.textfield.MaterialAutoCompleteTextView, define an ArrayAdapter and setting is layout adapter, but TextView is not wrapping correctly in the dropdown, on an regular Spinner, same ArrayAdapter works ok.
Expected behavior:
Both AutoCompleteTextView and Spinner.
AutoCompleteTextView dropDown won't wrap text.
Spinner dropDown works ok.
Source code:
Layout activity:
Code in activity:
mAdapterDomicilio = new ArrayAdapter<>(this, R.layout.list_item_multiline);
Item layout, for dropDown item in ArrayAdapter:
Minimal sample app repro: MyApplication.zip
Android API version: 33
Material Library version: 1.8.0
Device: All Devices