2017-06-27 2 views
1

Ich habe einen Konverter, der nur im Debug-Modus funktioniert. Wenn ich ein Release-APK erzeuge, funktioniert es nicht mehr.ColorStateList Converter funktioniert nur im Debug-Modus

Hier ist mein Code:

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; 
    } 
} 

Und mein 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> 

Es funktioniert perfekt im Debug-Modus. Hast du eine Ahnung, warum es passiert?

+0

Verwenden Sie eine Lib von Drittanbietern für 'Mvx.MvxImageView'? –

+0

Im Debug-Modus versuchen, den Linker zu aktivieren, erhalten Sie dann Fehler? – Cheesebaron

+0

Ich verwende nur SDK Assemblies, beide Fälle. DeBug und Freigabe. –

Antwort

0

Ich habe gerade die Lösung gefunden!

Ich verwende Verknüpfung, also, der Konverter funktionierte nicht, weil der Linker aktiviert war.

Ich lege diese Methode in eine Klasse namens "LinkerPleaseInclude".

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

Diese Klasse wird nie tatsächlich ausgeführt wird, aber wenn Xamarin Verknüpfung aktiviert ist es funktioniert, wie Arten zu gewährleisten und Eigenschaften werden in der entfalteten App erhalten.