Refine search
((GradientDrawable) checkedDrawable).setColor(mTintColor); ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor); ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor); ((GradientDrawable) uncheckedDrawable).setColor(mUnCheckedTintColor); int maskColor = Color.argb(50, Color.red(mTintColor), Color.green(mTintColor), Color.blue(mTintColor)); maskDrawable.setColor(maskColor); LayerDrawable pressedDrawable = new LayerDrawable(new Drawable[] {uncheckedDrawable, maskDrawable});
public static void setCustomizerDrawableColor(final View target, final int color) { final Drawable d = target.getDrawable(); LayerDrawable layer = (LayerDrawable)d; GradientDrawable gradient = (GradientDrawable)layer.getDrawable(0); gradient.setColor(color); gradient.invalidateSelf(); layer.invalidateSelf(); target.invalidate(); }
private void changeBackgroundColor(int color) { LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer .findDrawableByLayerId(R.id.shape_bacground); shape.setColor(color); }
public class Utils2 { public static void setBadgeCount(Context context, LayerDrawable icon, int count) { BadgeDrawable badge; // Reuse drawable if possible Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge); if (reuse != null && reuse instanceof BadgeDrawable) { badge = (BadgeDrawable) reuse; } else { badge = new BadgeDrawable(context); } badge.setCount(count); icon.mutate(); icon.setDrawableByLayerId(R.id.ic_badge, badge); } }
public static Drawable fromDrawable(Drawable drawable) { if (drawable != null) { if (drawable instanceof RoundedDrawable) { // just return if it's already a RoundedDrawable return drawable; } else if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; int num = ld.getNumberOfLayers(); // loop through layers to and change to RoundedDrawables if possible for (int i = 0; i < num; i++) { Drawable d = ld.getDrawable(i); ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d)); } return ld; } // try to get a bitmap from the drawable and Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm); } } return drawable; }
public static Drawable getDrawable(Drawable drawable, String colorname, int width) { GradientDrawable gradientDrawable = new GradientDrawable(); int color; try { color = Color.parseColor(colorname); } catch (Exception e) { color = Util.generateColorInt(); } gradientDrawable.setShape(GradientDrawable.OVAL); gradientDrawable.setBounds(0, 0, width, width); gradientDrawable.setColor(color); if (drawable == null) return gradientDrawable; Drawable[] array = new Drawable[2]; drawable.setBounds(0, 0, width, width); array[1] = drawable; array[0] = gradientDrawable; LayerDrawable layerDrawable = new LayerDrawable(array); layerDrawable.setLayerInset(0, 0, 0, 0, 0); layerDrawable.setLayerInset(1, 0, 0, 0, 0); layerDrawable.setBounds(0, 0, width, width); return layerDrawable; }
LayerDrawable layerDrawable = (LayerDrawable) v.getContext().getResources().getDrawable(R.drawable.layer_list_navigation_with_border); GradientDrawable strokeDrawable = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.item_bottom_stroke); strokeDrawable.setColor(strokeColor[0]); GradientDrawable backgroundColor = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.item_navbar_background); backgroundColor.setColors(bgColor);
void updateBackground() { LayerDrawable layerDrawable; if (mShowShadow) { layerDrawable = new LayerDrawable(new Drawable[]{ new Shadow(), createFillDrawable() }); int leftInset = mShadowRadius + Math.abs(mShadowXOffset); int topInset = mShadowRadius + Math.abs(mShadowYOffset); int rightInset = (mShadowRadius + Math.abs(mShadowXOffset)); int bottomInset = (mShadowRadius + Math.abs(mShadowYOffset)); layerDrawable.setLayerInset( 1, leftInset, topInset, rightInset, bottomInset ); } else { layerDrawable = new LayerDrawable(new Drawable[]{ createFillDrawable() }); } setBackgroundCompat(layerDrawable); }
private void updateAttrs(Drawable drawable, ScaleType scaleType) { if (drawable == null) { return; } if (drawable instanceof RoundedDrawable) { ((RoundedDrawable) drawable) .setScaleType(scaleType) .setBorderWidth(mBorderWidth) .setBorderColor(mBorderColor) .setOval(mIsOval) .setTileModeX(mTileModeX) .setTileModeY(mTileModeY); if (mCornerRadii != null) { ((RoundedDrawable) drawable).setCornerRadius( mCornerRadii[Corner.TOP_LEFT], mCornerRadii[Corner.TOP_RIGHT], mCornerRadii[Corner.BOTTOM_RIGHT], mCornerRadii[Corner.BOTTOM_LEFT]); } applyColorMod(); } else if (drawable instanceof LayerDrawable) { // loop through layers to and set drawable attrs LayerDrawable ld = ((LayerDrawable) drawable); for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) { updateAttrs(ld.getDrawable(i), scaleType); } } }
@Test public void testSetDrawableByLayerId1() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); int index = 1; int layerId = 345; layerDrawable.setId(index, layerId); layerDrawable.setDrawableByLayerId(layerId, drawable4000); assertEquals(shadowOf(drawable4000).getCreatedFromResId(), shadowOf(layerDrawable.getDrawable(index)).getCreatedFromResId()); }
private static StateListDrawable setupStateDrawable(ViewGroupPosition position, int strokeWidth, GradientDrawable defaultGd, GradientDrawable activeGd, GradientDrawable disabledGd) { StateListDrawable stateListDrawable = new StateListDrawable(); LayerDrawable defaultLayer = new LayerDrawable(new Drawable[]{defaultGd}); LayerDrawable activeLayer = new LayerDrawable(new Drawable[]{activeGd}); LayerDrawable disabledLayer = new LayerDrawable(new Drawable[]{disabledGd});
LayerDrawable layerDrawable = (LayerDrawable) getResources() .getDrawable(R.drawable.my_drawable); GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable .findDrawableByLayerId(R.id.gradientDrawble); gradientDrawable.setCornerRadius(50);
StateListDrawable gradientDrawable = (StateListDrawable) inflatedView.getBackground(); DrawableContainerState drawableContainerState = (DrawableContainerState) gradientDrawable.getConstantState(); Drawable[] children = drawableContainerState.getChildren(); LayerDrawable selectedItem = (LayerDrawable) children[0]; LayerDrawable unselectedItem = (LayerDrawable) children[1]; GradientDrawable selectedDrawable = (GradientDrawable) selectedItem.getDrawable(0); GradientDrawable unselectedDrawable = (GradientDrawable) unselectedItem.getDrawable(0); selectedDrawable.setStroke(STORKE_SIZE, NOTIFICATION_COLOR); unselectedDrawable.setStroke(STORKE_SIZE, NOTIFICATION_COLOR);
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar); LayerDrawable stars = (LayerDrawable) ratingBar.getProgressDrawable(); stars.getDrawable(2).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
@SuppressWarnings("ResourceAsColor") private void setDivider(AboutBuilder bundle, @NonNull View holder) { if (bundle.isShowDivider()) { int color = bundle.getDividerColor(); if (color == 0) color = isDarker() ? Color.GRAY : getNameColor(); GradientDrawable drawable = ((GradientDrawable) ((LayerDrawable) holder.getBackground()).findDrawableByLayerId(R.id.stroke)); if (drawable != null) { drawable.setStroke(bundle.getDividerHeight(), color, bundle.getDividerDashWidth(), bundle.getDividerDashGap()); } } else { RippleUtil.background(holder, (Drawable) null); } }
@Test public void setDrawableByLayerId_shouldReturnTrueIfIdWasFound() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); int index = 0; int layerId = 345; layerDrawable.setId(index, layerId); boolean ret = layerDrawable.setDrawableByLayerId(layerId, drawable4000); assertTrue(ret); } }
return null; } else { LayerDrawable layerDrawable = new LayerDrawable(drawables); for (int i = 0; i < drawables.length; i++) { int[] childLayersAttr = childLayersAttrs[i]; if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) { layerDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]); layerDrawable.setId(i, childLayersAttr[4]);
@Test public void testGetNumberOfLayers() { LayerDrawable layerDrawable = new LayerDrawable(drawables); assertEquals("count", 3, layerDrawable.getNumberOfLayers()); }
@Test public void setDrawableByLayerId_shouldReturnFalseIfIdNotFound() throws Exception { LayerDrawable layerDrawable = new LayerDrawable(drawables); boolean ret = layerDrawable.setDrawableByLayerId(123, drawable4000); assertFalse(ret); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menu); // i use a Relative Layout RelativeLayout rl = (RelativeLayout) findViewById(R.id.rlmenu); // Obtain then backgroud of RelativeLayout LayerDrawable layer = (LayerDrawable) rl.getBackground(); // obtain the image set in the Layer BitmapDrawable bg = (BitmapDrawable) layer.getDrawable(1); // create a new BitmapDrawable from the function Drawable d =new BitmapDrawable(getRoundedCornerBitmap(bg.getBitmap())); // set the new roundcorner image in the layer layer.setDrawableByLayerId(1, d); rl.setBackgroundDrawable(d); }