Refine search
TypedArray imgs = getResources().obtainTypedArray(R.array.random_imgs); // get resource ID by index imgs.getResourceId(i, -1) // or set you ImageView's resource to the id mImgView1.setImageResource(imgs.getResourceId(i, -1)); // recycle the array imgs.recycle();
TypedArray a = getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {R.attr.homeIcon}); int attributeResourceId = a.getResourceId(0, 0); Drawable drawable = getResources().getDrawable(attributeResourceId); a.recycle();
TypedArray ids = getResources().obtainTypedArray(R.array.random_imgs); // Get resource id by its index ids.getResourceId(index, -1); // be sure to call TypedArray.recycle() when done with the array ids.recycle();
int[] attrs = new int[]{R.attr.selectableItemBackground}; TypedArray typedArray = context.obtainStyledAttributes(attrs); int backgroundResource = typedArray.getResourceId(0, 0); view.setBackgroundResource(backgroundResource); typedArray.recycle();
public ImageAdapter(Context c) { mContext = c; TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); }
public AHBottomNavigationBehavior(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AHBottomNavigationBehavior_Params); mTabLayoutId = a.getResourceId(R.styleable.AHBottomNavigationBehavior_Params_tabLayoutId, View.NO_ID); a.recycle(); }
/** * Get the styleId from attributes. * @param context * @param attrs * @param defStyleAttr * @param defStyleRes * @return The styleId. */ public static int getStyleId(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ThemableView, defStyleAttr, defStyleRes); int styleId = a.getResourceId(R.styleable.ThemableView_v_styleId, 0); a.recycle(); return styleId; }
public TintCheckedTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray array = context.obtainStyledAttributes(attrs, ATTRS); final int drawLeftId = array.getResourceId(0, 0); final int drawLeftTintId = array.getResourceId(1, 0); array.recycle(); if (drawLeftId != 0 && drawLeftTintId != 0) { tintCheckTextView(drawLeftId, drawLeftTintId); } }
public LayoutParams(Context c, AttributeSet attrs) { super(c, attrs); TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.AppBarLayout_Layout); anchorView = a.getResourceId(R.styleable.AppBarLayout_Layout_carbon_anchor, -1); anchorGravity = a.getInt(R.styleable.AppBarLayout_Layout_carbon_anchorGravity, -1); a.recycle(); }
public PreferenceHelp(Context context, AttributeSet attrs) { super(context, attrs, R.attr.preferenceHelpStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PreferenceHelp); try { mLayoutResId = a.getResourceId(R.styleable.PreferenceHelp_dialogLayout, 0); mTitle = a.getString(R.styleable.PreferenceHelp_dialogTitle); } finally { a.recycle(); } }
final int resolveResIdAttr(@AttrRes int attrResId, int defResId) { mAttrs[0] = attrResId; TypedArray a = mTheme.obtainStyledAttributes(mAttrs); try { return a.getResourceId(0, defResId); } finally { a.recycle(); } }
public void setTextAppearanceForTextColor(int resId, boolean isForced) { boolean isTextColorForced = isForced || mTextColorId == 0; TypedArray appearance = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance); if (appearance.hasValue(R.styleable.TextAppearance_android_textColor) && isTextColorForced) { setTextColor(appearance.getResourceId(R.styleable.TextAppearance_android_textColor, 0)); } appearance.recycle(); }
public static int getThemeAttrId(Context context, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getResourceId(0, 0); } finally { a.recycle(); } }
/** * Get a resource id from a resource styled according to the the context's theme. */ public static int resolveResourceIdFromAttr(Context context, @AttrRes int attr) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr}); int attributeResourceId = a.getResourceId(0, 0); a.recycle(); return attributeResourceId; }
private static int resolveResourceIdFromAttr(Context context, @AttrRes int attr) { TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr}); int attributeResourceId = a.getResourceId(0, 0); a.recycle(); return attributeResourceId; } }
static int getAttrResourceId(Context context, AttributeSet attrs, int attr, int defaultValue) { TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final int id = a.getResourceId(0, defaultValue); a.recycle(); return id; }
public static int getThemeAttrId(Context context, AttributeSet attrs, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TypedArray a = context.obtainStyledAttributes(attrs, TEMP_ARRAY); try { return a.getResourceId(0, 0); } finally { a.recycle(); } }
TypedArray ar = context.getResources().obtainTypedArray(R.array.my_array); int len = ar.length(); int[] resIds = new int[len]; for (int i = 0; i < len; i++) resIds[i] = ar.getResourceId(i, 0); ar.recycle(); // Do stuff with resolved reference array, resIds[]... for (int i = 0; i < len; i++) Log.v (TAG, "Res Id " + i + " is " + Integer.toHexString(resIds[i]));
public static Context getThemedContext(Context context, AttributeSet attributeSet, int[] attrs, int defStyleAttr, int attr) { TypedArray a = context.obtainStyledAttributes(attributeSet, attrs, defStyleAttr, 0); if (a.hasValue(attr)) { int themeId = a.getResourceId(attr, 0); a.recycle(); return new CarbonContextThemeWrapper(context, themeId); } return context; }
private void parseAttributes(Context context, AttributeSet attrs) { TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.MultiToggleImageButton, 0, 0); int imageIds = a.getResourceId(R.styleable.MultiToggleImageButton_imageIds, 0); if (imageIds > 0) { overrideImageIds(imageIds); } a.recycle(); }