Home > database >  How to use Hex Code or or predefined color in ColorStateList.valueof()
How to use Hex Code or or predefined color in ColorStateList.valueof()

Time:11-09

I'm trying to change my fab's color programmaticaly.So I found this code block It's actually works but I need to use a specific color on my colors.xml file or hex code

ImageViewCompat.setImageTintList(
floatingActionButton,
ColorStateList.valueOf(Color.WHITE) );

CodePudding user response:

Change #FF0000 with your desired color

ImageViewCompat.setImageTintList(floatingActionButton,
ColorStateList.valueOf(Color.parseColor("#FF0000")));

for resource xml color

ImageViewCompat.setImageTintList(floatingActionButton,
ColorStateList.valueOf(ResourcesCompat.getColor(getResources(), R.color.your_color, null)));
  • Related