本文整理匯總了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();
}
}