It can be done in two ways
Options 1: Create an layout XML with your image button, and set that layout to action bar.
For example: In you activity copy the following lines.
ActionBar actionBar = getSupportActionBar();
LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);
actionBar.setCustomView(v);
Now display a PopUp menu
when the user clicks a ImageButton
.
Option 2:
Instead of setting the view
for the ActionBar
, you can use sub-Menu's
in the action bar. For this you need to create sub-Menu.
for example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/file"
android:icon="@drawable/ic_new_game"
android:title="@string/file" >
<!-- "file" submenu -->
<menu>
<item android:id="@+id/create_new"
android:title="@string/create_new" />
<item android:id="@+id/open"
android:title="@string/open" />
</menu>
</item>
</menu>
Set an icon for the main `MenuItem` so it looks like an `ImageButton`, when the user click the first MenuItem it displays the its sub-`Menu`