Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Exposed Drop-Down Menu in Android

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Exposed Drop-Down menu is the replacement for Spinner in Android because Spinner is not that customizable like the new exposed Drop-Down menu. Below is the sample GIF to give an idea of what we are going to build. Note that we are going to implement this project using the Kotlin language.

Exposed Drop-Down Menu in Android

Step by Step Implementation

Step 1: Create a new Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Kotlin as the programming language.

Step 2: Working with the activity_main.xml file

Go to the activity_main.xml file and refer to the following code. Below is the code for the activity_main.xml file.


<?xml version="1.0" encoding="utf-8"?>
    <!--Create a TextInputLayout and choose the style,
        for now we are choosing the OutlinedBox ExposedDropdownMenu   -->
        <!-- Inside text input layout add
              an auto complete text view
                and make its input type to none-->
            android:text="Choose Programming language"

Step 3: Add string array items to the string.xml file. We will use this data to inflate the drop-down items


<string-array name="programming_languages">

Step 4: Create a new layout file and name it a dropdown_item.xml file

Go to the dropdown_item.xml file and refer to the following code. Below is the code for the dropdown_item.xml file. It is the single-text view which we will use as a single item of the dropdown.


    android:text="TextView" />

Step 5: Working with MainActivity.kt

Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.AutoCompleteTextView
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        // get reference to the string array that we just created
        val languages = resources.getStringArray(R.array.programming_languages)
        // create an array adapter and pass the required parameter
        // in our case pass the context, drop down layout , and array.
        val arrayAdapter = ArrayAdapter(this, R.layout.dropdown_menu, languages)
        // get reference to the autocomplete text view
        val autocompleteTV = findViewById<AutoCompleteTextView>(
        // set adapter to the autocomplete tv to the arrayAdapter


My Personal Notes arrow_drop_up
Last Updated : 23 Jun, 2021
Like Article
Save Article
Similar Reads