Refine search
public static Drawable cornerDrawable(final int bgColor, float[] cornerradius, int borderwidth, int bordercolor) { final GradientDrawable bg = new GradientDrawable(); bg.setCornerRadii(cornerradius); bg.setStroke(borderwidth, bordercolor); bg.setColor(bgColor); return bg; }
public static Drawable cornerDrawable(final int bgColor, float cornerradius) { final GradientDrawable bg = new GradientDrawable(); bg.setCornerRadius(cornerradius); bg.setColor(bgColor); return bg; }
protected GradientDrawable createGradientDrawable(int color) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setShape(GradientDrawable.RECTANGLE); gradientDrawable.setColor(color); return gradientDrawable; }
private void setDrawable(GradientDrawable gd, int color, int strokeColor) { gd.setColor(color); gd.setCornerRadius(cornerRadius); gd.setStroke(strokeWidth, strokeColor); }
private GradientDrawable getGradientDrawable(int color, float radius) { GradientDrawable gradientDrawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, new int[]{color, color}); gradientDrawable.setShape(GradientDrawable.OVAL); gradientDrawable.setCornerRadius(radius); return gradientDrawable; }
/** * Called by the RecyclerView to display data at a specified position in the Cursor. * * @param holder The ViewHolder to bind Cursor data to * @param position The position of the data in the Cursor */ @Override public void onBindViewHolder(TaskViewHolder holder, int position) { // Indices for the _id, description, and priority columns int idIndex = mCursor.getColumnIndex(TaskContract.TaskEntry._ID); int descriptionIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_DESCRIPTION); int priorityIndex = mCursor.getColumnIndex(TaskContract.TaskEntry.COLUMN_PRIORITY); mCursor.moveToPosition(position); // get to the right location in the cursor // Determine the values of the wanted data final int id = mCursor.getInt(idIndex); String description = mCursor.getString(descriptionIndex); int priority = mCursor.getInt(priorityIndex); //Set values holder.itemView.setTag(id); holder.taskDescriptionView.setText(description); // Programmatically set the text and color for the priority TextView String priorityString = "" + priority; // converts int to String holder.priorityView.setText(priorityString); GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground(); // Get the appropriate background color based on the priority int priorityColor = getPriorityColor(priority); priorityCircle.setColor(priorityColor); }
((GradientDrawable) checkedDrawable).setColor(mTintColor); ((GradientDrawable) checkedDrawable).setStroke(mMarginDp, mTintColor); ((GradientDrawable) uncheckedDrawable).setStroke(mMarginDp, mTintColor); ((GradientDrawable) uncheckedDrawable).setColor(mUnCheckedTintColor); ((GradientDrawable) checkedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view)); ((GradientDrawable) uncheckedDrawable).setCornerRadii(mLayoutSelector.getChildRadii(view)); maskDrawable.setStroke(mMarginDp, mTintColor); maskDrawable.setColor(mUnCheckedTintColor); maskDrawable.setCornerRadii(mLayoutSelector.getChildRadii(view)); 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}); stateListDrawable.addState(StateSet.WILD_CARD, transitionDrawable); mDrawableMap.put(view.getId(), transitionDrawable); view.setBackground(stateListDrawable); } else { view.setBackgroundDrawable(stateListDrawable);
@Override public void onBindHeaderColumnViewHolder(@NonNull ViewHolderImpl viewHolder, int column) { int color = COLORS[column % COLORS.length]; TestHeaderColumnViewHolder vh = (TestHeaderColumnViewHolder) viewHolder; vh.tvText.setText(mTableDataSource.getColumnHeaderData(column)); // skip left top header GradientDrawable gd = new GradientDrawable( mIsRtl ? GradientDrawable.Orientation.RIGHT_LEFT : GradientDrawable.Orientation.LEFT_RIGHT, new int[]{ColorUtils.setAlphaComponent(color, 50), 0x00000000}); gd.setCornerRadius(0f); vh.vGradient.setBackground(gd); vh.vLine.setBackgroundColor(color); }
mRectDrawable.setColor(mBarColor); mRectDrawable.setStroke((int) mBarStrokeWidth, mBarStrokeColor); mRectDrawable.setCornerRadius(mIndicatorCornerRadius); mRectDrawable.setBounds(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom()); mRectDrawable.draw(canvas); for (int i = 0; i < mTabCount - 1; i++) { View tab = mTabsContainer.getChildAt(i); canvas.drawLine(paddingLeft + tab.getRight(), mDividerPadding, paddingLeft + tab.getRight(), height - mDividerPadding, mDividerPaint); mIndicatorDrawable.setColor(mIndicatorColor); mIndicatorDrawable.setBounds(paddingLeft + (int) mIndicatorMarginLeft + mIndicatorRect.left, (int) mIndicatorMarginTop, (int) (paddingLeft + mIndicatorRect.right - mIndicatorMarginRight), (int) (mIndicatorMarginTop + mIndicatorHeight)); mIndicatorDrawable.setCornerRadii(mRadiusArr); mIndicatorDrawable.draw(canvas);
GradientDrawable shape = new GradientDrawable(); shape.setCornerRadius( 8 ); // add some color // You can add your random color generator here // and set color if (i % 2 == 0) { shape.setColor(Color.RED); } else { shape.setColor(Color.BLUE); } // now find your view and add background to it View view = (LinearLayout) findViewById( R.id.my_view ); view.setBackground(shape);
private void changeBackgroundColor(int color) { LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer .findDrawableByLayerId(R.id.shape_bacground); shape.setColor(color); }
public void setBackgroundColor(int color){ this.backgroundColor = color; if(isEnabled()) beforeBackground = backgroundColor; LayerDrawable layer = (LayerDrawable) progressView.getBackground(); GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); shape.setColor(color); super.setBackgroundColor(makePressColor()); }
//use a GradientDrawable with only one color set, to make it a solid color GradientDrawable border = new GradientDrawable(); border.setColor(0xFFFFFFFF); //white background border.setStroke(1, 0xFF000000); //black border with full opacity if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { TitleLayout.setBackgroundDrawable(border); } else { TitleLayout.setBackground(border); }
private void setViewColor(View view, int color) { if (view.getBackground() instanceof GradientDrawable) { GradientDrawable drawable = (GradientDrawable) view.getBackground().mutate(); drawable.setColor(color); } }
public static Drawable cornerDrawable(final int bgColor, float[] cornerradius) { final GradientDrawable bg = new GradientDrawable(); bg.setCornerRadii(cornerradius); bg.setColor(bgColor); return bg; }
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(); }
GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.setColor(selected_color); gradientDrawable.setCornerRadius(cornerRadius); selected = new InsetDrawable(gradientDrawable, paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); GradientDrawable gradientMask = new GradientDrawable(); gradientMask.setColor(Color.BLACK); gradientMask.setCornerRadius(cornerRadius); Drawable mask = new InsetDrawable(gradientMask, paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); } else { GradientDrawable touchDrawable = new GradientDrawable(); touchDrawable.setColor(UIUtils.getThemeColor(ctx, R.attr.colorControlHighlight)); touchDrawable.setCornerRadius(cornerRadius); Drawable touchInsetDrawable = new InsetDrawable(touchDrawable, paddingStartEnd, paddingTopBottom, paddingStartEnd, paddingTopBottom); view.setForeground(unselected); } else { states.addState(new int[]{android.R.attr.state_selected}, selected);
View layout = findViewById(R.id.mainlayout); GradientDrawable gd = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {0xFF616261,0xFF131313}); gd.setCornerRadius(0f); layout.setBackgroundDrawable(gd);
@Test public void testGetColor_returnsColor() throws Exception { GradientDrawable gradientDrawable = new GradientDrawable(); ShadowGradientDrawable shadowGradientDrawable = shadowOf(gradientDrawable); int color = 123; gradientDrawable.setColor(color); assertThat(shadowGradientDrawable.getLastSetColor()).isEqualTo(color); } }