попробуйте этот простой пример
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tvWelcome = findViewById(R.id.tv_welcome);
TextView tvHello = findViewById(R.id.tv_hello);
recolor(this, tvWelcome, getResources().getColor(R.color.red));
recolor(this, tvHello, getResources().getColor(R.color.green));
}
private void recolor(Context context, TextView textView, @ColorInt int color) {
Drawable unwrappedDrawable = AppCompatResources.getDrawable(context, R.drawable.item_background);
if (unwrappedDrawable != null) {
DrawableCompat.wrap(unwrappedDrawable);
DrawableCompat.setTint(unwrappedDrawable, color);
textView.setBackground(unwrappedDrawable);
}
}
}
item_background. xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff" />
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>