Issue
I have the following gradient (generated dynamically):
GradientDrawable dynamicDrawable = new GradientDrawable();
dynamicDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
dynamicDrawable.setUseLevel(false);
int colors[] = new int[3];
colors[0] = Color.parseColor("#711234");
colors[1] = Color.parseColor("#269869");
colors[2] = Color.parseColor("#269869");
dynamicDrawable.setColors(colors);
and I want to set that drawable in a view using onDraw method.
When I want to assign a Drawable to a bitmap I use the casting (BitmapDrawable), but in that case is not possible due the gradientDrawable cannot be cast to BitmapDrawable.
Any idea about how I solve that?
Thanks in advance
Solution
- Create a mutable bitmap using
Bitmap.createBitmap() - Create a
Canvasbased on the bitmap usingnew Canvas(bitmap) - Then call
draw(canvas)on yourGradientDrawable
Answered By - kris larson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.