Java Code Examples for android.graphics.drawable.GradientDrawable#mutate()
The following examples show how to use
android.graphics.drawable.GradientDrawable#mutate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColoringActivity.java From coloring with GNU General Public License v3.0 | 6 votes |
/** * Updates the color of the color picker selected button with the actual color (a gradient from it). */ private void updateColorOfColorPickerButton() { View view = findViewById(R.id.colorPickerButton); // takes the actually selected color int color = Library.getInstance().getSelectedColor(); int[] gradientColors = ColoringUtils.colorSelectionButtonBackgroundGradient(color); if (Build.VERSION.SDK_INT < 16) { GradientDrawable newGradientDrawable = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, gradientColors); newGradientDrawable.setStroke(1, Color.parseColor("#bbbbbb")); newGradientDrawable.setCornerRadius(ColoringActivity.this.getResources().getDimension(R.dimen.color_selection_button_corner_radius)); //noinspection deprecation view.setBackgroundDrawable(newGradientDrawable); } else { GradientDrawable drawable = (GradientDrawable) view.getBackground(); drawable.mutate(); drawable.setColors(gradientColors); } }
Example 2
Source File: Drawable_Color_Util.java From AGIKSwipeButton with MIT License | 5 votes |
public static void setDrawableStroke(Drawable drawable, int color) { if (drawable instanceof GradientDrawable) { GradientDrawable gradientDrawable = (GradientDrawable) drawable; gradientDrawable.mutate(); gradientDrawable.setStroke(4, color); } }
Example 3
Source File: Util.java From slideview with MIT License | 5 votes |
static void setDrawableStroke(Drawable drawable, int color) { if (drawable instanceof GradientDrawable) { GradientDrawable gradientDrawable = (GradientDrawable) drawable; gradientDrawable.mutate(); gradientDrawable.setStroke(4, color); } }
Example 4
Source File: ProductAdapter.java From From-design-to-Android-part1 with Apache License 2.0 | 5 votes |
@NonNull private GradientDrawable createProductBackground(Product product) { final GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable( itemView.getContext(), R.drawable.bg_product); gradientDrawable.setColor(ContextCompat.getColor( itemView.getContext(), product.color)); gradientDrawable.setSize(itemView.getWidth(), getDrawableHeight()); gradientDrawable.mutate(); return gradientDrawable; }
Example 5
Source File: ButtonCompat.java From 365browser with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void updateButtonBackgroundL() { ColorStateList csl = new ColorStateList( new int[][] { { -android.R.attr.state_enabled }, {} }, new int[] { DISABLED_COLOR, mColor }); GradientDrawable shape = (GradientDrawable) ((RippleDrawable) getBackground()).getDrawable(0); shape.mutate(); shape.setColor(csl); }