It is possible for items of the ActionBar
. You have to define the item that you want to have a different selector as a custom action view.
<item
android:id="@+id/menu_custom"
android:actionLayout="@layout/action_view"
android:showAsAction="always"/>
In the layout referenced by android:actionLayout
you have an ImageView
that you assign your selector and make it clickable and focusable.
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/action_view_background"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:minWidth="56dip"
android:paddingBottom="8dip"
android:paddingTop="8dip"
android:src="@drawable/ic_launcher" />
The click event is not handled by onOptionsItemSelected
. You have to attach an OnClickListener
in onCreateOptionsMenu
.
menu.findItem(R.id.menu_custom).getActionView().setOnClickListener(l);