Material Design Spinner
How to use this material design "spinner"
I'm just going to be honest and say this was stupid. It pissed me off because why would you remove a spinner to essentially make a text view? Google got too many people to be this annoying to devs. Anyway let me show you the xml and the kotlin code...
XML
fragment_main.xml
<com.google.android.material.textfield.TextInputLayout
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="@string/select_one"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<AutoCompleteTextView
android:id="@+id/dropdown_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"/>
</com.google.android.material.textfield.TextInputLayout>
list_item_dropdown.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceSubtitle1"/>
Kotlin File
MainFragment.kt
private var list = listOf("word 1", "word 2", "word 3")
val adapter = ArrayAdapter(requireContext(), R.layout.list_item_dropdown, actionList)
binding.dropdownValue.setAdapter(adapter)
binding.dropdownValue.setOnItemClickListener { parent, view, position, id ->
Log.d("FRAG", list[position])
}
I do believe this is a cleaner dropdown menu but figuring this stuff out took like 2 days and I think that's a lot for something that should be simple. Regardless I hope this helps someone out. Save yourself time and prosper.