I would like to just put a button on the'Action Bar '.
follows a sample image from the internet.
You need to add a method called onCreateOptionsMenu , example:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
Within the res directory, you must create the menu directory, and within the menu directory, you create the main .xml .
Here is an example of the menu XML:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/action_back"
android:icon="@drawable/ic_back"
android:orderInCategory="100"
app:showAsAction="always" />
</menu>
Each item you add in XML will be a button on your ActionBar .