Whenever you create a Blank Activity in Android Studio, a menu resource directory (i.e. menu resource file i.e. res/menu) and file gets automatically created, with auto-generated code in java class file. But what if you want to add an Empty Activity, can you create a menu resource directory and file manually? The answer is yes, this is what we will cover in this post.
What we will learn?
- The difference between Blank Activity and Empty Activity?
- How to add an Empty Activity in Android Studio?
- How to create a menu resource directory (res/menu)?
- How to create a menu resource file in menu resource directory (res/menu/menu_main.xml).
Before moving further, since we will be discussing Blank Activity and Empty Activity, here are the differences
between both the activities,
Here are the steps with which you can easily add a menu resource directory and file in Empty Activity in Android Studio,
Adding Menu Resource Directory (res/menu)
Step 1: Open your project and right click on res, then click “New”, then “Android resource directory”,
After that change the resource type to “menu” in the dropdown menu and then click “OK”
Now you can see a new Android Resource Directory “menu” gets created,
Adding menu file in Menu Resource Directory
Step 1: To create menu file in menu folder, right click on “menu” directory, “New”, then click “Menu resource file“,
Step 2: Give the file name, menu_main.xml -> click Ok,
Step 3: Now, you can see the directory structure, that shows the new file, “menu_main.xml” in “menu” directory.
Here’s the video showing the above steps,
Editorial Staff at Generic Whiz.