1.
I'm creating a custom Theme, let's call it TestABS with parent the HOLO Theme ( in our case Sherlock ).
So now in my styles.xml I add the line :
<style name="Theme.TestABS" parent="@style/Theme.Sherlock"></style>
2.
Later I'll edit Manifest file like this :
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.TestABS"
android:logo="@drawable/ad_logo">
3.
When Activity starts, the system adds ActionBar and the overflow menu by calling onCreateOptionsMenu().
This method inflates an XML resource which defines the menu items. This files is in the folder
So a simple item should be like :
<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="Text Here" />
This works as long as I have an ActionBar in my Activity( When do I have an ActionBar ? When I add android:theme="@style/Theme.HOLO" in my manifest file for android 3.0 and greater. For lower versions I need Theme.Sherlock . In both cases I can declare mine custom theme like I did above with TestABS ).
Links :
1) Adding ActionBarSherlock to your Project
2) Adding Items to the ActionBar
3) The Overflow menu ( As a rule of thumb you should always use
I'm creating a custom Theme, let's call it TestABS with parent the HOLO Theme ( in our case Sherlock ).
So now in my styles.xml I add the line :
<style name="Theme.TestABS" parent="@style/Theme.Sherlock"></style>
2.
Later I'll edit Manifest file like this :
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.TestABS"
android:logo="@drawable/ad_logo">
3.
When Activity starts, the system adds ActionBar and the overflow menu by calling onCreateOptionsMenu().
This method inflates an XML resource which defines the menu items. This files is in the folder
/res/menu.
In those items on the XML file I have to add the android:showAsAction keyword, so now the items will appear as Action Items in my ActionBar and not Options Menu.So a simple item should be like :
<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom"
android:title="Text Here" />
This works as long as I have an ActionBar in my Activity( When do I have an ActionBar ? When I add android:theme="@style/Theme.HOLO" in my manifest file for android 3.0 and greater. For lower versions I need Theme.Sherlock . In both cases I can declare mine custom theme like I did above with TestABS ).
Links :
1) Adding ActionBarSherlock to your Project
2) Adding Items to the ActionBar
3) The Overflow menu ( As a rule of thumb you should always use
ifRoom
, if you want the icon to be part of your action bar and you should use never
if you want the item to always be part of the overflow menu. )