本文整理汇总了Java中android.view.MenuItem.SHOW_AS_ACTION_ALWAYS属性的典型用法代码示例。如果您正苦于以下问题:Java MenuItem.SHOW_AS_ACTION_ALWAYS属性的具体用法?Java MenuItem.SHOW_AS_ACTION_ALWAYS怎么用?Java MenuItem.SHOW_AS_ACTION_ALWAYS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.MenuItem
的用法示例。
在下文中一共展示了MenuItem.SHOW_AS_ACTION_ALWAYS属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseMenu
private void parseMenu(XmlPullParser parser, AttributeSet attrs)
throws XmlPullParserException, IOException {
int eventType = parser.getEventType();
String tagName;
boolean lookingForEndOfUnknownTag = false;
String unknownTagName = null;
// This loop will skip to the menu start tag
do {
if (eventType == XmlPullParser.START_TAG) {
tagName = parser.getName();
if (tagName.equals("menu")) {
// Go to next tag
eventType = parser.next();
break;
}
throw new RuntimeException("Expecting menu, got " + tagName);
}
eventType = parser.next();
} while (eventType != XmlPullParser.END_DOCUMENT);
boolean reachedEndOfMenu = false;
while (!reachedEndOfMenu) {
switch (eventType) {
case XmlPullParser.START_TAG:
if (lookingForEndOfUnknownTag) {
break;
}
tagName = parser.getName();
if (tagName.equals("item")) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MenuItem);
int itemShowAsAction = a.getInt(R.styleable.MenuItem_showAsAction, -1);
if((itemShowAsAction & MenuItem.SHOW_AS_ACTION_ALWAYS) != 0) {
int itemId = a.getResourceId(R.styleable.MenuItem_android_id, NO_ID);
if(itemId != NO_ID) mAlwaysShowingMenu.add(itemId);
}
a.recycle();
} else {
lookingForEndOfUnknownTag = true;
unknownTagName = tagName;
}
break;
case XmlPullParser.END_TAG:
tagName = parser.getName();
if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
lookingForEndOfUnknownTag = false;
unknownTagName = null;
} else if (tagName.equals("menu")) {
reachedEndOfMenu = true;
}
break;
case XmlPullParser.END_DOCUMENT:
throw new RuntimeException("Unexpected end of document");
}
eventType = parser.next();
}
}