public void inflate(@MenuRes int menuRes, Menu menu) {
XmlResourceParser parser = null;
try {
parser = mContext.getResources().getLayout(menuRes);
AttributeSet attrs = Xml.asAttributeSet(parser);
parseMenu(parser, attrs, menu);
} catch (XmlPullParserException e) {
throw new InflateException(“Error inflating menu XML”, e);
} catch (IOException e) {
throw new InflateException(“Error inflating menu XML”, e);
} finally {
if (parser != null) parser.close();
}
}
最终会调用到下面的setItem()
方法
private void setItem(MenuItem item) {
…省略部分代码
boolean actionViewSpecified = false;
if (itemActionViewClassName != null) {
View actionView = (View) newInstance(itemActionViewClassName,
ACTION_VIEW_CONSTRUCTOR_SIGNATURE, mActionViewConstructorArguments);
item.setActionView(actionView);