Another quick and clean way to do this is to specify your own layout for this menu button. something like that
<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="com.example.MainActivity"> <item android:id="@+id/action_custom_button" android:title="Custom Button" android:icon="@drawable/ic_custom_button" app:actionLayout="@layout/layout_to_custom_button" app:showAsAction="always" /> </menu>
should be
layout_to_custom_button.xml
layout file that contains the desired add-on and style.
and also do it in your activity for the click event
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_product_detail, menu); final Menu mMenu = menu; final MenuItem item = menu.findItem(R.id.action_custom_button); item.getActionView().setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { mMenu.performIdentifierAction(item.getItemId(), 0); } }); return true; }
source share