By default when you add items in Android’s action bar, the icon will not be shown if it will be shown as overflow.
To make sure an icon appears beside the menu item label like this:
Add a sub menu tag within the item tag like this:
Since this menu item in the action bar is forced to become overflow permanently (appear as icon all the time), I extracted the PNG file ic_action_overflow from the Android menu icon pack and set it to this menu item.
This is it. The XML code above should display the way as the image posted above.
I thought that creating a custom method in my Activity class where I can change the visibility of a MenuItem and accessing it from the Fragment would work. Sadly, it did not.
It seems that the Fragment class has a method called setHasOptionsMenu(boolean) and you need to call that from within the onCreateView() method in order to be able to manipulate MenuItems from within onCreateOptionsMenu().
So this is how a sample Fragment class will look like.