Sometimes you got your color in color file and you want to use that one.
WHAT YOU CAN DO IS THIS CODE BELOW
fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor(getString(R.color.youcolor))));
As you know to change it programmatically, you need to use setBackgroundTintList()
, then pass the ColorStateList.valueOf()
which is required and this one take a certein int and parse it...
Note: if you just put the int color right away it could give you problems to get the color you want sometimes and for that reason i don't use it and don't recommend it to use it like that
Then put within ColorStateList.valueOf()
, Color.parseColor()
this is what you need to put...
This needs a String but you have the int color in the color file, so what to do?
Within Color.parseColor()
pass getString()
, this is a method that each activity has, so within getString()
you put finally your color as this R.color.yourcolor