4

I am creating a custom view by extending android.view.View.

Now, I need to draw a rounded rectangle on API level below 21. Android has a built in method name,drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) in android.graphics.Canvas, but It doesn't support API below 21, but I need to draw this on API 16. How can I achieve that?

Thanks in advance

touhid udoy
  • 4,005
  • 2
  • 18
  • 31
  • 5
    `Canvas#drawRoundRect` was introduced in API level 1, read the [official docs](https://developer.android.com/reference/android/graphics/Canvas) for more info – pskink Oct 28 '18 at 08:43
  • thanks for fast feedback. I edited my ques, `drawRect(Rect r, Paint paint)` is available in API 1 but `drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint)` in added in API 21 – touhid udoy Oct 28 '18 at 11:14
  • did you see the link i posted? did you try to press `^F` followed by `drawRoundRect`? – pskink Oct 28 '18 at 11:18
  • yes, i got it, thanks for reply – touhid udoy Oct 28 '18 at 12:26

1 Answers1

10

I got my solution after all!

Although drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) is added in API level 21, there is another method, drawRect (RectF rect,Paint paint) which is added in API level 1 that can be used instead.

Thanks pskink for the guide.

Example:

Rectf rectf= new Rectf(left, top, right, bottom);
canvas.drawRoundRect(rectf,rx,ry, mPaint);
touhid udoy
  • 4,005
  • 2
  • 18
  • 31