Create your account

Already have an account? Login here

Create account

80. Add Menu in XML

Design + Code an Android App from Scratch

Woah, wait a second..

Scrounge up some loose change to become a pro member, or login to your account to view this lesson.

Alright, join now. Or login to your account if you're already a pro member.

This video shows how to add a menu to our Activity in Android. In the first step, create a folder called menu under res in your project directory. Right click on the folder and select new menu resource file. Call it whatever you want and after creating it, you’ll notice an XML file with a root menu tag inside it. Inside the menu tag, create as many item tags as you want and each item needs to have a title which is compulsory and an icon which is optional. The showAsAction attribute controls whether we see the menu item in the top app bar or action bar of our Activity. Override the onCreateOptionsMenu in the Activity to inflate the xml menu file using a MenuInflater object which you can retrieve by calling getMenuInflater inside our Activity. Finally override the onOptionsItemSelected method to handle menu item clicks inside our Activity.

Course Cirriculum