我收到以下警告:
绑定代码:
<TextView
android:id="@+id/text_view_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
style="@style/text_group_header"
app:MvxBind="Text DisplayHeader; TextColor AppointmentFeedHeaderGroupColor(StartTime)"
/>
AppointmentFeedHeaderGroupColorValueConverter.cs
public class AppointmentFeedHeaderGroupColorValueConverter: MvxValueConverter<DateTime, Color>
{
private static readonly IDateTimeService DateTimeService = Mvx.Resolve<IDateTimeService>();
private static readonly Color HeaderGroupBlack = GetColor(Resource.Color.black);
private static readonly Color HeaderGroupRedLight = GetColor(Resource.Color.red_light);
protected override Color Convert(DateTime value, Type targetType, object parameter, CultureInfo culture)
{
if (value != DateTimeService.Now.Date)
{
return HeaderGroupRedLight;
}
return HeaderGroupBlack;
}
private static Color GetColor(int resourceColorId)
{
var context = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;
return new Color(ContextCompat.GetColor(context, resourceColorId));
}
}
我在文件 LinkerPleaseInclude.cs 中添加了以下代码。
public void Include(TextView text)
{
text.AfterTextChanged += (sender, args) => text.Text = "" + text.Text;
text.Hint = "" + text.Hint;
text.SetTextColor(Color.Black);
var tc = text.TextColors;
text.SetTextColor(tc);
}
它没有帮助
首先,检查MvvmCross.Plugin.Color
您的Android
项目和PCL/NetStandard
项目中是否都安装了。
然后您的转换器应该在您的 PCL/NetStandard 项目中并从中继承,MvxColorValueConverter<DateTime>
以便您的颜色不依赖于您的平台:
public class AppointmentFeedHeaderGroupColorValueConverter: MvxColorValueConverter<DateTime>
{
private static readonly IDateTimeService DateTimeService = Mvx.Resolve<IDateTimeService>();
private static readonly MvxColor HeaderGroupBlack = new MvxColor(0,0,0);
private static readonly MvxColor HeaderGroupRedLight = new MvxColor(255,0,0); // red_light, should see how to convert this to RGB values
protected override MvxColor Convert(DateTime value, object parameter, CultureInfo culture)
{
if (value != DateTimeService.Now.Date)
{
return HeaderGroupRedLight;
}
return HeaderGroupBlack;
}
}
最后,像您目前所做的那样使用颜色转换器:
TextColor AppointmentFeedHeaderGroupColor(StartTime)
更多信息:
MvvmCross.Plugin.Color.MvxColorValueConverter.cs
在这里,您拥有MvvmCross提供的完整LinkerPleaseInclude文件。
HIH
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句