With the Material Components Library you can use the MaterialShapeDrawable
.
<TextView
android:id="@+id/textview"
.../>
Then you can programmatically apply a MaterialShapeDrawable
:
TextView textView = findViewById(R.id.textview);
MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable();
shapeDrawable.setFillColor(ContextCompat.getColorStateList(this,android.R.color.transparent));
shapeDrawable.setStroke(1.0f, ContextCompat.getColor(this,R.color....));
ViewCompat.setBackground(textView,shapeDrawable);