I have an ImageView
that I attach to a MenuItem
as its ActionView
(the item appears in the ActionBar
). The layout for this vi
I would simply do it like this:
menuItem.setActionView(R.layout.action_view_layout);
Let Android inflate the view for you.
If you need to do some extra changes on this ImageView call
ImageView imageView = (ImageView) menuItem.getActionView();
Update
In order to cater to your curiosity. That is what folks from Google do under the hood:
public MenuItem setActionView(int resId) {
final Context context = mMenu.getContext();
final LayoutInflater inflater = LayoutInflater.from(context);
setActionView(inflater.inflate(resId, new LinearLayout(context), false));
return this;
}