Example usage for android.content.res XmlResourceParser getIdAttributeResourceValue

List of usage examples for android.content.res XmlResourceParser getIdAttributeResourceValue

Introduction

In this page you can find the example usage for android.content.res XmlResourceParser getIdAttributeResourceValue.

Prototype

public int getIdAttributeResourceValue(int defaultValue);

Source Link

Document

Return the integer value of the "id" attribute or defaultValue if there is none.

Usage

From source file:com.roughike.bottombar.TabParser.java

@NonNull
private BottomBarTab parseNewTab(@NonNull XmlResourceParser parser, @IntRange(from = 0) int containerPosition) {
    BottomBarTab workingTab = tabWithDefaults();
    workingTab.setIndexInContainer(containerPosition);

    final int numberOfAttributes = parser.getAttributeCount();
    for (int i = 0; i < numberOfAttributes; i++) {
        @TabAttribute/*from w  ww.  jav a  2  s .  co m*/
        String attrName = parser.getAttributeName(i);
        switch (attrName) {
        case ID:
            workingTab.setId(parser.getIdAttributeResourceValue(i));
            break;
        case ICON:
            workingTab.setIconResId(parser.getAttributeResourceValue(i, RESOURCE_NOT_FOUND));
            break;
        case TITLE:
            workingTab.setTitle(getTitleValue(parser, i));
            break;
        case INACTIVE_COLOR:
            int inactiveColor = getColorValue(parser, i);
            if (inactiveColor == COLOR_NOT_SET)
                continue;
            workingTab.setInActiveColor(inactiveColor);
            break;
        case ACTIVE_COLOR:
            int activeColor = getColorValue(parser, i);
            if (activeColor == COLOR_NOT_SET)
                continue;
            workingTab.setActiveColor(activeColor);
            break;
        case BAR_COLOR_WHEN_SELECTED:
            int barColorWhenSelected = getColorValue(parser, i);
            if (barColorWhenSelected == COLOR_NOT_SET)
                continue;
            workingTab.setBarColorWhenSelected(barColorWhenSelected);
            break;
        case BADGE_BACKGROUND_COLOR:
            int badgeBackgroundColor = getColorValue(parser, i);
            if (badgeBackgroundColor == COLOR_NOT_SET)
                continue;
            workingTab.setBadgeBackgroundColor(badgeBackgroundColor);
            break;
        case BADGE_HIDES_WHEN_ACTIVE:
            boolean badgeHidesWhenActive = parser.getAttributeBooleanValue(i, true);
            workingTab.setBadgeHidesWhenActive(badgeHidesWhenActive);
            break;
        case IS_TITLELESS:
            boolean isTitleless = parser.getAttributeBooleanValue(i, false);
            workingTab.setIsTitleless(isTitleless);
            break;
        }
    }

    return workingTab;
}