2017-06-27 29 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鏈接它如何確保類型和屬性在部署應用程序保留。

相關問題