I'm using com.google.android.material.textfield.TextInputLayout with style Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu and using also AutoCompleteTextView. These make the input as dropdown list. But the issue right now is long text of list won't show the complete item text. How can I show all the text and make it multiline?
<com.google.android.material.textfield.TextInputLayout
style="@style/CustomStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_input">
<AutoCompleteTextView
android:id="@+id/autocomplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:inputType="none" />
</com.google.android.material.textfield.TextInputLayout>
themes.xml
<style name="LayoutDropdown" parent="Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu">
<item name="boxBackgroundColor">@color/white</item>
<item name="android:textColor">@color/black</item>
<item name="colorControlNormal">@color/black</item>
<item name="colorControlActivated">@color/black</item>
<item name="colorControlHighlight">@color/black</item>
</style>
Java
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.dropdown_menu_item, list);
AutoCompleteTextView dropdown = findViewById(R.id.autocomplete);
dropdown.setAdapter(adapter);
dropdown.setKeyListener(null);
dropdown_menu_item.xml
<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"/>
Here is the result. It doesn't show full text on selection dropdown.
Change the layout used for each item.
Use something like:
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.dropdown_menu_item,R.id.item, list);
with:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
...
/>
</LinearLayout>
Also if you want to display the long text also in the AutoCompleteTextView
use android:inputType="textMultiLine"
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.