Create Options Menu in ActionBar in Android using Jetpack Compose Last Updated : 30 Mar, 2022 Comments Improve Suggest changes Like Article Like Report In Android, ac ActionBar or a TopBar is a UI element that is present at the top of the activity screen. An ActionBar by default displays the activity name inside it. However, we can add other elements like the back button, images, options menu, etc inside an ActionBar. So in this article, we will show you how you could Create Options Menu in ActionBar in Android using Jetpack Compose. Follow the below steps once the IDE is ready. Step by Step Implementation Step 1: Create a New Project in Android Studio To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project. Step 2: Working with the MainActivity.kt file 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. Kotlin package com.geeksforgeeks.jcactionbarmenuoptions import android.os.Bundle import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Favorite import androidx.compose.material.icons.filled.MoreVert import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { // Calling the composable function // to display element and its contents MainContent() } } } // Creating a composable function // to display Top Bar and options menu @Composable fun MainContent() { // Create a boolean variable // to store the display menu state var mDisplayMenu by remember { mutableStateOf(false) } // fetching local context val mContext = LocalContext.current // Creating a Top bar TopAppBar( title = { Text("GFG | Menu Options", color = Color.White) } ,backgroundColor = Color(0xff0f9d58), actions = { // Creating Icon button favorites, on click // would create a Toast message IconButton(onClick = { Toast.makeText(mContext, "Favorite", Toast.LENGTH_SHORT).show() }) { Icon(Icons.Default.Favorite, "") } // Creating Icon button for dropdown menu IconButton(onClick = { mDisplayMenu = !mDisplayMenu }) { Icon(Icons.Default.MoreVert, "") } // Creating a dropdown menu DropdownMenu( expanded = mDisplayMenu, onDismissRequest = { mDisplayMenu = false } ) { // Creating dropdown menu item, on click // would create a Toast message DropdownMenuItem(onClick = { Toast.makeText(mContext, "Settings", Toast.LENGTH_SHORT).show() }) { Text(text = "Settings") } // Creating dropdown menu item, on click // would create a Toast message DropdownMenuItem(onClick = { Toast.makeText(mContext, "Logout", Toast.LENGTH_SHORT).show() }) { Text(text = "Logout") } } } ) } // For displaying preview in // the Android Studio IDE emulator @Preview(showBackground = true) @Composable fun DefaultPreview() { MainContent() } Output: You can see that we are able to create options menu as well as a drop-down menu as seen in the below output video. Comment More infoAdvertise with us Next Article Create Options Menu in ActionBar in Android using Jetpack Compose aashaypawar Follow Improve Article Tags : Kotlin Android Android-Jetpack Similar Reads Swiping Action Box in Android using Jetpack Compose If you are an Android user, you must have seen applications that display the list of items and each of those items could be dragged left or right to perform some particular action. Gmail application for Android is the most common example, where you can drag an item left or right from the inbox to ar 3 min read Floating Action Button in Android using Jetpack Compose Floating Action Button is added to the android application to perform some important within the android application. These are implemented in the android application UI for some primary actions within the application. There are different types of floating action buttons such as simple, square, and e 3 min read Jetpack Compose Navigation and Passing Data in Android Almost every app uses some kind of navigation, allows users to move from one screen to another. In this article, we will learn to implement Navigation in Jetpack Compose using Compose way. We will build a simple app demonstrating Jetpack compose navigation, It will have three screens(Home, Profile, 4 min read How to Create Outlined Text in Android using Jetpack Compose? In Android, we can customize various aspects of a Text for displaying them accordingly. We can change the font size, and font family as well as apply various functions like bold, italics, etc. However, it is not possible to display an outline font for the same text. In case, you are unaware of what 3 min read Deep Links in Android using Jetpack Compose A deep link is a URL that is used to direct users to a specific page or specific activity within the application. We can also pass data to our application with the help of these deep links. In this article, we will take a look at How to implement Deep Links in Android using Jetpack Compose. Step by 7 min read How to Add Margin in Android using Jetpack Compose? In Android, Padding is used to offset the content of the view by a specific number of pixels from either direction, i.e., padding from left, right, top and bottom. Using Padding, we can create multiple borders to a view by applying a combination of multiple padding and border.  So in this article, 2 min read Multi Touch Gestures in Android using Jetpack Compose Android provides a variety of tools and methods using which we can create different types of transformations. These transformations could be applied to any view or element and can be operated upon touch. The most common transformation is zooming in and out which is available on applications like Int 3 min read Drop-Down Menu in Android using Jetpack Compose In Android, a TextField is used to take text-based input from the user to perform a particular task. This text can be general text or be specific to characters, numbers, etc. However, this is not the only purpose of implementing a TextField. A TextField can also be converted into a drop-down menu di 3 min read Implement IME Action Buttons in Soft Keyboard in Android using Jetpack Compose In Android, IME (Input Method Action) Action Button is a key on the Soft Keyboard that represents different actions that can be displayed. In the below image, we have located the IME Action Buttons of two different types. In the below image, you can see the different types of actions that can be dis 3 min read Start a New Activity using Intent in Android using Jetpack Compose In Android OS, an Intent is a mechanism used to navigate a user to another activity or application to achieve a specific task. In general, Intents are used to progress to the next activity or come back to the previous activity. In this article, we will show you how you could start a New Activity usi 3 min read Like