public DividerItemDecoration(Context context, AttributeSet attrs) { final TypedArray a = context .obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider}); mDivider = a.getDrawable(0); a.recycle(); }
// Create an array of the attributes we want to resolve // using values from a theme int[] attrs = new int[] { R.attr.listItemBackground /* index 0 */}; // Obtain the styled attributes. 'themedContext' is a context with a // theme, typically the current Activity (i.e. 'this') TypedArray ta = themedContext.obtainStyledAttributes(attrs); // To get the value of the 'listItemBackground' attribute that was // set in the theme used in 'themedContext'. The parameter is the index // of the attribute in the 'attrs' array. The returned Drawable // is what you are after Drawable drawableFromTheme = ta.getDrawable(0 /* index */); // Finally, free the resources used by TypedArray ta.recycle();
public StartAnimatable(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.StartAnimatable); Drawable drawable = a.getDrawable(R.styleable.StartAnimatable_android_src); a.recycle(); if (drawable instanceof Animatable) { animatable = (Animatable) drawable; } else { throw new IllegalArgumentException("Non-Animatable resource provided."); } }
public SupportGridItemDecoration(Context context) { final TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); }
public DividerDecoration(Context context) { final TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); }
public AdvanceDecoration(Context context,int orientation) { TypedArray typedArray=context.obtainStyledAttributes(attrs); mDivider=typedArray.getDrawable(0); typedArray.recycle(); this.orientation=orientation; } @Override
divider = styledAttributes.getDrawable(0); styledAttributes.recycle();
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundView, defStyle, 0); final Drawable d = a.getDrawable(R.styleable.ForegroundView_android_foreground); if (d != null) { setForeground(d); } a.recycle(); }
ImageView myIcon; //... TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MyLayout); Drawable drawable = a.getDrawable(R.styleable.MyLayout_icon); if (drawable != null) myIcon.setBackgroundDrawable(drawable);
public AlbumMediaAdapter(Context context, SelectedItemCollection selectedCollection, RecyclerView recyclerView) { super(null); mSelectionSpec = SelectionSpec.getInstance(); mSelectedCollection = selectedCollection; TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{R.attr.item_placeholder}); mPlaceholder = ta.getDrawable(0); ta.recycle(); mRecyclerView = recyclerView; }
@Nullable static Drawable getBackgroundOrDefault(ComponentContext c, Drawable specifiedBackground) { if (specifiedBackground != null) { return specifiedBackground; } final int[] attrs = {android.R.attr.background}; TypedArray a = c.getAndroidContext().obtainStyledAttributes(null, attrs, android.R.attr.editTextStyle, 0); Drawable defaultBackground = a.getDrawable(0); a.recycle(); return defaultBackground; }
public DividerItemDecoration(Context context, int orientation) { final TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); setOrientation(orientation); }
public SupportDividerItemDecoration(Context context, int orientation, boolean dash) { if (dash) { mDivider = ContextCompat.getDrawable(context, R.drawable.shape_common_dash_divide); } else { final TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); } setOrientation(orientation); }
public YourView(Context context, AttributeSet attrs) { super(context, attrs); int[] set = { android.R.attr.background, // idx 0 android.R.attr.text // idx 1 }; TypedArray a = context.obtainStyledAttributes(attrs, set); Drawable d = a.getDrawable(0); CharSequence t = a.getText(1); Log.d(TAG, "attrs " + d + " " + t); a.recycle(); }
public DividerItemDecoration(Context context, int orientation) { final TypedArray a = context.obtainStyledAttributes(ATTRS); mDivider = a.getDrawable(0); a.recycle(); setOrientation(orientation); }
public ForegroundImageView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundView); final Drawable d = a.getDrawable(R.styleable.ForegroundView_android_foreground); if (d != null) { setForeground(d); } a.recycle(); setOutlineProvider(ViewOutlineProvider.BOUNDS); }
public ForegroundRelativeLayout(Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundView); final Drawable d = a.getDrawable(R.styleable.ForegroundView_android_foreground); if (d != null) { setForeground(d); } a.recycle(); setOutlineProvider(ViewOutlineProvider.BOUNDS); }
public IcsLinearLayout(Context context, int themeAttr) { super(context); TypedArray a = context.obtainStyledAttributes(null, LL, themeAttr, 0); setDividerDrawable(a.getDrawable(IcsLinearLayout.LL_DIVIDER)); mDividerPadding = a.getDimensionPixelSize(LL_DIVIDER_PADDING, 0); mShowDividers = a.getInteger(LL_SHOW_DIVIDER, SHOW_DIVIDER_NONE); a.recycle(); }
static Drawable getAttrDrawable(Context context, AttributeSet attrs, int attr) { final TypedArray a = obtainAttributes(context.getResources(), context.getTheme(), attrs, new int[]{attr}); final int resId = a.getResourceId(0, 0); Drawable drawable = null; if (resId != 0) { drawable = createDrawable(context, resId); if (drawable == null) { drawable = a.getDrawable(0); } } a.recycle(); return drawable; }
@Test public void getDrawable_withExplicitColorValue_shouldReturnColorDrawable() throws Exception { TypedArray typedArray = context.obtainStyledAttributes( Robolectric.buildAttributeSet() .addAttribute(android.R.attr.background, "#ff777777") .build(), new int[]{android.R.attr.background}); ColorDrawable drawable = (ColorDrawable) typedArray.getDrawable(0); assertThat(drawable.getColor()).isEqualTo(0xff777777); }