With the Material Components Library you can use the MaterialShapeDrawable
to draw custom shapes.
With a TextView you can do:
<TextView
android:id="@+id/tv_rounded"
android:paddingLeft="8dp"
../>
Then create a MaterialShapeDrawable
. Something like:
TextView textview = findViewById(R.id.tv_rounded);
ShapeAppearanceModel shapeAppearanceModel = new ShapeAppearanceModel()
.toBuilder()
.setAllCorners(CornerFamily.ROUNDED,radius)
.setBottomRightCorner(CornerFamily.ROUNDED,0)
.setBottomLeftCorner(CornerFamily.ROUNDED,0)
.build();
MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
shapeDrawable.setStroke(2.0f, ContextCompat.getColor(this,R.color.xxxx));
shapeDrawable.setFillColor(ContextCompat.getColorStateList(this,R.color.xxx));
ViewCompat.setBackground(textview,shapeDrawable);
