I want to change a single menuItem background
in android but it's not working. What I did, set a appcompat supported actionview
in MenuItem
and trying to set background
of actionview
.
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">
<item android:id="@+id/action_my_balance"
android:title="@string/my_balance"
app:showAsAction="never"
app:actionViewClass="android.widget.ImageButton"
/>
</menu>
source code
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_menu, menu);
ImageButton balanceMenu = (ImageButton) MenuItemCompat.getActionView(menu.findItem(R.id.action_my_balance));
balanceMenu.setBackgroundColor(Color.RED);
balanceMenu.invalidate();
return true;
}
But it's not working at all. Also is it possible to getView on MenuItem without set custom actionview
?