I have a custom drawable using <shape> in xml, with the following code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/blue"/>
<corners
android:radius="150dp"/>
</shape>
on a button, and I would like to programmatically change the button's color to another color while keeping the shape it gets from the custom drawable. Is this possible?
CodePudding user response:
If you dont want to use the normal backgrounTint in your xml folder :
android:backgroundTint="yourcolor"
Use this Code in your java code :
yourbutton.setBackgroundTintList(this.getResources().getColorStateList(R.color.colorname));