Issue
I'm using GradientDrawable for applying corner radius on a rectangle, this drawable is finally set on a TextView
val drawable = GradientDrawable()
drawable.shape = GradientDrawable.RECTANGLE
drawable.setStroke(3, Color.YELLOW)
drawable.setColor(Color.RED)
drawable.cornerRadius = 10.toFloat()
view.setBackgroundDrawable(drawable)
Do you have any idea of why isn't working and is still a rectangle without corner radius being applied?
I tried calling mutate()
before but still not working and also tried the cornerRadii but nothing :(
Solution
Here example
for how to create GradientDrawable
shape programmatically.
GradientDrawable shape = new GradientDrawable();
shape.setShape(GradientDrawable.RECTANGLE);
shape.setColor(Color.RED);
shape.setStroke(3, Color.YELLOW);
For change the radius for all corners of the gradient.
shape.setCornerRadius(15);
For Change the radius for specific corners of the gradient.
shape.setCornerRadii(new float[] { 8, 8, 8, 8, 0, 0, 0, 0 });
You can use this drawable as a background as below :
view.setBackgroundDrawable(shape);
Fore more details click here
Answered By - S_i_l_e_n_t C_o_d_e_r
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.