Android TypedArray - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android TypedArray class.

This code example shows how to use the following methods:getDimensionPixelSize, getDrawable, getInteger, recycle
This code example shows how to use the following methods:getBoolean, getIndex, getResourceId, recycle
        mContext=context;
        mVisibilityController = new VisibilityController(this);
        TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
        		android.R.attr.windowTitleStyle,
                android.R.attr.defaultValue });
        mIsLegacy = a.getBoolean(a.getIndex(1 /* defaultValue */), false);
        if (mIsLegacy) {
            mTitleResource = a.getResourceId(a.getIndex(0 /* windowTitleStyle */), 0);
        } else { 
            a.recycle();
            a = context.obtainStyledAttributes(null,
                    new int[] { android.R.attr.titleTextStyle,
                            android.R.attr.subtitleTextStyle },
                    android.R.attr.actionBarStyle,
                    0); 
            mTitleResource = a.getResourceId(a.getIndex(0 /* titleTextStyle */), 0);
            mSubtitleResource = a.getResourceId(a.getIndex(1 /* subtitleTextStyle */), 0);
        } 
        a.recycle();
    } 

8
CodeRank
This code example shows how to use the following methods:getBoolean, recycle
This code example shows how to use the following methods:getString, peekValue, recycle
    private static final String INTENT_TAG_NAME = "intent";
 
    private static void parseBundleExtra(Resources resources, String tagName, AttributeSet attrs,
                                         Bundle outBundle) throws XmlPullParserException {
        TypedArray sa = resources.obtainAttributes(attrs, R.styleable.Extra);
        String name = sa.getString(R.styleable.Extra_android_name);
        if (name == null) {
            sa.recycle();
            throw new XmlPullParserException("<" + tagName
                    + "> requires an holo:name attribute at " 
                    + attrs.getPositionDescription());
        } 
        TypedValue v = sa.peekValue(R.styleable.Extra_android_value);
        if (v != null) {
            if (v.type == TypedValue.TYPE_STRING) {
                CharSequence cs = v.coerceToString();
                outBundle.putCharSequence(name, cs);
            } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) {
                outBundle.putBoolean(name, v.data != 0);
            } else if (v.type >= TypedValue.TYPE_FIRST_INT

8
CodeRank
This code example shows how to use the following methods:getBoolean, getIndex, getResourceId, recycle
        mContext=context;
        mVisibilityController = new VisibilityController(this);
        TypedArray a = context.obtainStyledAttributes(attrs, new int[] {
        		android.R.attr.windowTitleStyle,
                android.R.attr.defaultValue });
        mIsLegacy = a.getBoolean(a.getIndex(1 /* defaultValue */), false);
        if (mIsLegacy) {
            mTitleResource = a.getResourceId(a.getIndex(0 /* windowTitleStyle */), 0);
        } else { 
            a.recycle();
            a = context.obtainStyledAttributes(null,
                    new int[] { android.R.attr.titleTextStyle,
                            android.R.attr.subtitleTextStyle },
                    android.R.attr.actionBarStyle,
                    0); 
            mTitleResource = a.getResourceId(a.getIndex(0 /* titleTextStyle */), 0);
            mSubtitleResource = a.getResourceId(a.getIndex(1 /* subtitleTextStyle */), 0);
        } 
        a.recycle();
    } 

8
CodeRank
This code example shows how to use the following methods:getDimensionPixelSize, getDrawable, getInteger, recycle
This code example shows how to use the following methods:getIndex, getResourceId, recycle
This code example shows how to use the following methods:getBoolean, getDimensionPixelSize, getDrawable, getInt, recycle
	public IcsLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
 
        TypedArray a = context.obtainStyledAttributes(attrs, /*com.android.internal.R.styleable.*/R_styleable_LinearLayout);
 
        setDividerDrawable(a.getDrawable(/*com.android.internal.R.styleable.*/LinearLayout_divider));
        mShowDividers = a.getInt(/*com.android.internal.R.styleable.*/LinearLayout_showDividers, SHOW_DIVIDER_NONE);
        mDividerPadding = a.getDimensionPixelSize(/*com.android.internal.R.styleable.*/LinearLayout_dividerPadding, 0);
        mUseLargestChild = a.getBoolean(/*com.android.internal.R.styleable.*/LinearLayout_measureWithLargestChild, false);
 
        a.recycle();
    } 
 
    /** 
     * Set how dividers should be shown between items in this layout 
     * 
     * @param showDividers One or more of {@link #SHOW_DIVIDER_BEGINNING}, 
     *                     {@link #SHOW_DIVIDER_MIDDLE}, or {@link #SHOW_DIVIDER_END}, 
     *                     or {@link #SHOW_DIVIDER_NONE} to show no dividers. 
     */ 
7
CodeRank
This code example shows how to use the following methods:getDrawable, recycle
	} 
 
	public ActionBarHomeAsUpIndicator(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
		final TypedArray a = context.obtainStyledAttributes(new int[] { android.R.attr.homeAsUpIndicator });
		final Drawable d = a.getDrawable(0);
		a.recycle();
		setImageDrawable(d);
		setScaleType(ScaleType.CENTER);
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:getResourceId, recycle
 
	public ActionBarSubtitleView(final Context context, final AttributeSet attrs, final int defStyle) {
		super(context, attrs, defStyle);
		final TypedArray a = context.obtainStyledAttributes(null, new int[] { android.R.attr.subtitleTextStyle },
				android.R.attr.actionBarStyle, android.R.style.Widget_Holo_ActionBar);
		final int textAppearance = a.getResourceId(0, android.R.style.Widget_Holo_ActionBar);
		a.recycle();
		setTextAppearance(context, textAppearance);
	} 
 
} 
7
CodeRank

Related Android TypedArray Questions & Answers:

Other Android TypedArray Examples

11:		// slide menu items
12:		private String[] navMenuTitles;
13:		private TypedArray navMenuIcons;
14:	
15:		private ArrayList<NavDrawerItem> navDrawerItems;

Read More

33:		// slide menu items
34:		private String[] navMenuTitles;
35:		private TypedArray navMenuIcons;
36:	
37:		private ArrayList<NavDrawerItem> navDrawerItems;

Read More

See Code Examples for Android TypedArray Methods: