@@ -688,15 +688,9 @@ public static String colorToHexString(int color) {
688688 public static void colorFloatingActionButton (FloatingActionButton button , @ DrawableRes int drawable ,
689689 Context context ) {
690690 int primaryColor = ThemeUtils .primaryColor (null , true , false , context );
691- colorFloatingActionButton (button , context , primaryColor );
692691
693- if (Color .BLACK == primaryColor ) {
694- button .setImageDrawable (ThemeUtils .tintDrawable (drawable , Color .WHITE ));
695- } else if (Color .WHITE == primaryColor ) {
696- button .setImageDrawable (ThemeUtils .tintDrawable (drawable , Color .BLACK ));
697- } else {
698- button .setImageDrawable (ThemeUtils .tintDrawable (drawable , ThemeUtils .fontColor (context , false )));
699- }
692+ colorFloatingActionButton (button , context , primaryColor );
693+ button .setImageDrawable (ThemeUtils .tintDrawable (drawable , getColorForPrimary (primaryColor , context )));
700694 }
701695
702696 public static void colorFloatingActionButton (FloatingActionButton button , Context context ) {
@@ -712,6 +706,29 @@ public static void colorFloatingActionButton(FloatingActionButton button, int ba
712706 button .setRippleColor (rippleColor );
713707 }
714708
709+ public static void colorIconImageViewWithBackground (ImageView imageView , Context context ) {
710+ int primaryColor = ThemeUtils .primaryColor (null , true , false , context );
711+
712+ imageView .getBackground ().setColorFilter (primaryColor , PorterDuff .Mode .SRC_IN );
713+ imageView .getDrawable ().mutate ().setColorFilter (getColorForPrimary (primaryColor , context ),
714+ PorterDuff .Mode .SRC_IN );
715+ }
716+
717+ /**
718+ * returns a primary color matching color for texts/icons on top of a primary-colored element (like buttons).
719+ *
720+ * @param primaryColor the primary color
721+ */
722+ private static int getColorForPrimary (int primaryColor , Context context ) {
723+ if (Color .BLACK == primaryColor ) {
724+ return Color .WHITE ;
725+ } else if (Color .WHITE == primaryColor ) {
726+ return Color .BLACK ;
727+ } else {
728+ return ThemeUtils .fontColor (context , false );
729+ }
730+ }
731+
715732 private static OCCapability getCapability (Context context ) {
716733 return getCapability (null , context );
717734 }
0 commit comments