To add a button to action bar, locate the onCreateOptionsMenu method in the activity with the action bar that you want to add the button to.
Next go to res>menu>main and add the item based on this example:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings" //<-- id of the view
android:orderInCategory="100" //<-- not important for the moment (importance)
android:showAsAction="never" //<-- this will always put it in overflow. set always to show as action
android:icon="@drawable/ic_launcher"/> //<-- Icon to display in action bar
android:title="@string/action_settings"/> //<-- not really important
</menu>
next, we will want to listen for item clicks, so add this method to your activity:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// action with ID action_settings was selected
case R.id.action_settings:
// this is where you put your own code to do what you want.
break;
default:
break;
}
return true;
}
And there ya go!