From the course: Building an Android App with Jetpack Libraries

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Add an options menu to the main fragment

Add an options menu to the main fragment - Android Tutorial

From the course: Building an Android App with Jetpack Libraries

Start my 1-month free trial

Add an options menu to the main fragment

- [Instructor] Now that I've defined my database, I'm ready to start adding some data to it. The user will be able to add sample data to the database by selecting an option from the options menu. So I have to create that menu. I'll go to my resource directory and I'll create a new Android resource file. I'll name it menu underscore main for the main fragment, and I'll set the resource type to menu and create it. And I'll look at that menu file in design mode. I just need one menu item, so I'll drag it in. And with that item selected, I'll go to the attributes panel over here, and I'll set the ID for this menu item to action sample data and I'll set the title to add sample data. I'll look at that in code view, and then I'll click into that literal string and I'll extract that as a string resource and now the menu is ready to use. Next, I'll go to my main fragment. I'll add a couple of override functions here. I'll start…

Contents