2017-06-27 43 views
1

我有一个只能在调试模式下工作的转换器。当我生成一个Release .apk时,它不再起作用。ColorStateList Converter只能在调试模式下工作

这里是我的代码:

public class CardapioImageColorConverter : MvxValueConverter<bool, ColorStateList> 
{ 
    private static Activity Activity => Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity; 
    protected override ColorStateList Convert(bool value, Type targetType, object parameter, CultureInfo culture) 
    { 
     ColorStateList color; 
     if (value) 
      color = Activity.Resources.GetColorStateList(Resource.Color.cor1,Activity.Theme); 
     else 
      color = Activity.Resources.GetColorStateList(Resource.Color.white, Activity.Theme); 

     return color; 
    } 
} 

而且我axml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:local="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="70dp" 
    android:layout_height="70dp"> 
    <Mvx.MvxImageView 
     android:id="@+id/imageView" 
     android:layout_weight="1" 
     android:tint="@color/white" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     local:MvxBind="ImageUrl Icone;ImageTintList CardapioImageColor(Selecionado);" 
     android:layout_gravity="center" /> 
    <TextView 
     local:MvxBind="Text Nome; TextColor CardapioTextColor(Selecionado);" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textColor="@color/cor1" 
     android:textSize="11dp" 
     android:layout_weight="1.9" 
     android:text="@string/lista_espera" 
     android:gravity="center" 
     android:layout_marginBottom="@dimen/margin_tiny" 
     android:layout_marginTop="@dimen/margin_tiny" /> 
</LinearLayout> 

它完全在调试模式。你有什么想法为什么会发生?

+0

你对Mvx.MvxImageView使用任何第三方库吗? –

+0

在调试模式下,尝试启用链接器,那么你会得到任何错误? – Cheesebaron

+0

我只用sdk Assemblies,这两种情况。 DeBug和Release。 –

回答

0

我刚找到解决方案!

我正在使用链接,所以,转换器不工作,因为链接器已启用。

我把这个方法放在一个名为“LinkerPleaseInclude”的类中。

public void Include(MvxImageView mvxImage) 
    { 
     mvxImage.ImageTintList = mvxImage.ImageTintList; 
    } 

这个类是从来没有真正执行,但如果启用了Xamarin链接它如何确保类型和属性在部署应用程序保留。

相关问题