How can I assign Hex or RGB color to the MvxColor

2019-07-11 07:01发布

问题:

I have converter like below in that I want to return my own Hex or RGB color.

In iOS

public class PinkSelectedWhiteUnselectedValueConverter : MvxValueConverter<bool, UIColor> {
    UIColor purePink = UIColor.FromRGB(233, 60, 172);
protected override UIColor Convert(bool value, Type targetType,object parameter, CultureInfo culture) {
    return (bool)value ? purePink : UIColor.White;
  }
}

it's working fine

But in Android, it's not working

 public class PinkSelectedWhiteUnSelectedValueConverter : MvxValueConverter<bool, Color> {
     
  Color colorPink = (Color)new  System.Drawing.ColorConverter().ConvertFromString("#e93cac");
  

   protected override Color Convert(bool value, Type targetType, object parameter, CultureInfo culture) {
          
  return (bool)value ? colorPink : Color.White;
        
   }
   
 }

Please help me on that thanks in advance.

回答1:

What you are looking for is something like this :

Color colorPink = Android.Graphics.Color.ParseColor("#e93cac");

or else something like this

Color purePink = Color.Rgb((int)r,(int) g,(int) b)