知识的领域是无限的,我们的学习也是无限期的。这篇文章主要讲述绑定MvvmCross TextColor不适用于Android相关的知识,希望能为你提供帮助。
我收到以下警告:
- [WARN](MvxBind)无法为MvxValueConverterValueCombiner组合器操作创建绑定TextColor的目标绑定
<
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));
}
}
【绑定MvvmCross TextColor不适用于Android】我在文件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 valuesprotected override MvxColor Convert(DateTime value, object parameter, CultureInfo culture)
{
if (value != DateTimeService.Now.Date)
{
return HeaderGroupRedLight;
}return HeaderGroupBlack;
}
}
最后,使用当前正在执行的颜色转换器:
TextColor AppointmentFeedHeaderGroupColor(StartTime)
更多信息:
MvvmCross Color docs
MvvmCross.Plugin.Color.MvxColorValueConverter.cs
在这里,您有MvvmCross提供的完整LinkerPleaseInclude文件。
HIH
推荐阅读
- Apple Mach-O链接器(id)错误 - 链接器命令失败,退出代码为1(使用-v查看调用)C ++ SFML
- 在Terraform Azure App服务资源中配置CORS
- 我的Eclipse插件中找不到自定义log4j appender
- 如何为Android Studio编写插件()
- Android SDK中的Eclipse Marketplace在哪里
- 如何解决`E Qt JAVA(找不到Surface 1-通过意图恢复到Qt @ android应用程序时出错())
- Solr Realtime获取RemoteSolrException(预期的mime类型application / xml但是得到了text / html)
- 需要修复在Azure App服务上运行的Angular 2的路由问题
- Android双向绑定转换器@InverseMethod不起作用