Saturday, June 7, 2014

Tambah Action Bar

Specify the Actions in XML


All action buttons and other items available in the action overflow are defined in an XML menu resource. To add actions to the action bar, create a new XML file in your project's res/menu/ directory.
Add an  element for each item you want to include in the action bar. For example:
res/menu/main_activity_actions.xml
 xmlns:android="http://schemas.android.com/apk/res/android" >
    
     android:id="@+id/action_search"
          android:icon="@drawable/ic_action_search"
          android:title="@string/action_search"
          android:showAsAction="ifRoom" />
    
     android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:showAsAction="never" />

Download action bar icons

This declares that the Search action should appear as an action button when room is available in the action bar, but the Settings action should always appear in the overflow. (By default, all actions appear in the overflow, but it's good practice to explicitly declare your design intentions for each action.)