Reputation: 1109
I have a custom background for a TextView like that:
<?xml version="1.0" encoding="utf-8"?>
<corners android:radius="45dp"/>
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp"/>
I want to change many color of it dynamically. So I have tried to change background color by:
title.setBackgroundColor(ContextCompat.getColor(mContext, R.color.red));
But after i change background color, I can not see the corner of it. How can I change color dynamically for that textview ?
Upvotes: 0
Views: 500
Reputation: 1215
That happens because by using title.setBackgroundColor()
you are replacing your custom background hence the corners disappear.
Try retrieving the drawable instead and change its color.
GradientDrawable titleDrawable = (GradientDrawable) title.getBackground();
titleDrawable.setColor(Color.RED)
Upvotes: 1