Exposed Drop-Down Menu in Android
In this article, we will explore the Exposed Drop-Down Menu in Android. With the help of the Exposed Drop-Down Menu, we can quickly and easily select an item from a list.
Let’s learn the use of Exposed Drop-Down Menu with a simple app that asks the user how they are feeling today.
Step 1
Create a new project in Android Studio.
Step 2
Open the activity_main.xml. Add a TextView to write the question text.
Then add a TextInputLayout that contains an AutoCompleteTextView to use Exposed Drop-Down Menu.
You can choose the style you want for Exposed Drop-Down Menu with the style property in TextInputLayout.
You can put a title in your Exposed Drop-Down Menu with hint property in TextInputLayout.
You can put an icon in your Exposed Drop-Down Menu with the startIconDrawable property in TextInputLayout.
Step 3
Go to strings.xml and add string array items there.
Step 4
Create a new layout file called dropdown_item.xml and add a TextView that will represent a single item of the Exposed Drop-Down Menu.
Step 5
Open the MainActivity.kt and create a variable named feelings and get a reference to the string array. Then create an array adapter and pass the context, dropdown layout, and array. Finally, set adapter to the autoCompleteTextView to the arrayAdapter.
Step 6
Run your application.
Mission accomplished! Thanks for reading.
For the complete code: