Learn how to add Action Items to the Action Bar

You should now be familiar with the Android Themes from the last Article.

Action Bars can be used to add items or shortcuts. Like if the user wants to quickly search for something or add something or even modify the app settings.

Let’s see how you can add such functionality.

There are three primary components which needs to be modified.

1. Menu resource file for the activity.
2. The onCreateOptionsMenu method.
3. The onOptionsItemSelected method.

You can find the menu resource file in the /menu folder. It’s auto generated by the Android Studio when you create a new Project.

The other two methods needs to be overridden in the Activity.

Follow the video to understand how to add this feature. Source code is available here.

Note : For the ThemeDemoApp you need to first remove the v7 dependency, as it creates a conflict when you try to use showAsAction attribute.

Author: androidsmartly

I am a Tech Enthusiast who likes to work on new Ideas. Sharing knowledge on Android, Marketing, Startups and More.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s