Friday, 7 January 2022

AutoCompleteTextView - How to remove margin from top and bottom?

I'm creating a dropdown menu using AutoCompleteTextView. How do I remove the default margins at the top and bottom of the list?

enter image description here

To recreate:

<com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:boxBackgroundColor="@color/white"
        android:focusable="false"
        app:boxStrokeWidth="1.5dp"
        app:layout_constraintTop_toBottomOf="@+id/spinner_network">

        <AutoCompleteTextView
            android:id="@+id/autoCompleteTextView"
            android:layout_width="250dp"
            android:layout_height="match_parent"
            android:inputType="none"
            android:dropDownHeight="200dp"
            android:text="Select age" />

    </com.google.android.material.textfield.TextInputLayout>
        List<String> dropdownItems = new ArrayList<>();
        for(int i = 1; i <= 100; i++){
            dropdownItems.add(String.valueOf(i));
        }

        ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(
                this, R.layout.dropdown_item, dropdownItems
        );

        AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
        autoCompleteTextView.setAdapter(spinnerAdapter);

R.layout.dropdown_item

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:textColor="@color/black"
    android:padding="14dp"
    android:layout_height="wrap_content"
    android:text="TextView" />


from AutoCompleteTextView - How to remove margin from top and bottom?

No comments:

Post a Comment