1

I'm working with Xamarin Studio 6.1.3 and trying the latest Xamarin Android Support Design library 25.3.1, my target is set to API 24 and min version is 19.

I have my Floating Action Button defined like this in my axml:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:src="@mipmap/check_in_icon"
    android:layout_marginRight="30dp"
    android:layout_marginBottom="30dp"
    app:backgroundTint="@color/check_in" />

I want the background tint color to change programmatically, which I tried to do with the following code:

fab.BackgroundTintList = GetInProgressColor();

Where GetInProgressColor method is:

    public ColorStateList GetInProgressColor()
    {
        ColorStateList csl = new ColorStateList(new int[][] { new int[0] }, new int[] { Color.ParseColor("#f43636") });
        return csl;
    }

But when my code calls the BackgroundTintList property at runtime I get the error:

Java.Lang.NoSuchMethodError: no method with name='setBackgroundTintList' signature='(Landroid/content/res/ColorStateList;)V' in class Landroid/view/View;
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3511/501e63ce/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
  at Java.Interop.JniEnvironment+InstanceMethods.GetMethodID (Java.Interop.JniObjectReference type, System.String name, System.String signature) [0x00068] in /Users/builder/data/lanes/3511/501e63ce/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11240
  at Java.Interop.JniType.GetInstanceMethod (System.String name, System.String signature) [0x0000f] in /Users/builder/data/lanes/3511/501e63ce/source/Java.Interop/src/Java.Interop/Java.Interop/JniType.cs:228
  at Java.Interop.JniPeerMembers+JniInstanceMethods.GetMethodInfo (System.String encodedMember) [0x0003a] in /Users/builder/data/lanes/3511/501e63ce/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:94
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00023] in /Users/builder/data/lanes/3511/501e63ce/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:25
  at Android.Views.View.set_BackgroundTintList (Android.Content.Res.ColorStateList value) [0x0002c] in /Users/builder/data/lanes/3511/501e63ce/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Views.View.cs:4324
  at QAbogados.Droid.Activities.AssigmentsActivity.SetInProgressStatus () [0x00043] in /Users/enapsys/Documents/QAbogados/git/QAbogados/UI/Droid/Activities/AssigmentsActivity.cs:391
  at QAbogados.Droid.Presenters.AssignmentPresenter.SetCurrentAssignmentLifecycle (System.String currentLifecycle) [0x00072] in /Users/enapsys/Documents/QAbogados/git/QAbogados/UI/Droid/Presenters/AssignmentPresenter.cs:85
  at QAbogados.Droid.Presenters.AssignmentPresenter+<GetAssignment>c__AnonStorey0.<>m__0 () [0x00066] in /Users/enapsys/Documents/QAbogados/git/QAbogados/UI/Droid/Presenters/AssignmentPresenter.cs:50
  at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/3511/501e63ce/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/3511/501e63ce/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Java.Lang.IRunnable.cs:81
  at at (wrapper dynamic-method) System.Object:baf8fb03-caca-4702-aa94-6d110a79963c (intptr,intptr)
  at java.lang.NoSuchMethodError: no method with name='setBackgroundTintList' signature='(Landroid/content/res/ColorStateList;)V' in class Landroid/view/View;
  at at mono.java.lang.RunnableImplementor.n_run(Native Method)
  at at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
  at at android.os.Handler.handleCallback(Handler.java:733)
  at at android.os.Handler.dispatchMessage(Handler.java:95)
  at at android.os.Looper.loop(Looper.java:136)
  at at android.app.ActivityThread.main(ActivityThread.java:5057)
  at at java.lang.reflect.Method.invokeNative(Native Method)
  at at java.lang.reflect.Method.invoke(Method.java:515)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
  at at dalvik.system.NativeStart.main(Native Method)

Why is throwing this error? I should be able to modify the background tint color since I'm using the Design Support Library, I'm able to display the Floating Action Button so I should be able modify it's properties, or is there a different way to manipulate its properties at runtime?

Uriel Arvizu
  • 1,876
  • 6
  • 37
  • 97
  • What API version are you running this on? There's a note of: This will always take effect when running on API v21 or newer. When running on platforms previous to API v21, it will only take effect if view implements the TintableBackgroundView interface. – Jon Douglas May 26 '17 at 19:43
  • So do I have to create a class that inherits from the Floating Action Button and implements this interface? Or is the implementation you refer to different? Please provide an example of this if you can. – Uriel Arvizu May 26 '17 at 19:51
  • Can you please answer my previous question beforehand? As for your second question, you have other options: https://stackoverflow.com/questions/33638873/android-setbackgroundtintlist-on-pre-lollipop-devices – Jon Douglas May 26 '17 at 19:58
  • I'm running on API 19 – Uriel Arvizu May 26 '17 at 19:59
  • I tried using `ViewCompat.setBackgroundTintList(fab, new ColorStateList(new int[][] { new int[0] }, new int[] { Color.ParseColor("#000000") }))` that should have tinted my FAB background white if I'm not mistaken but the color didn't change. The other thing I tried was to cast my FAB to AppCompatButton but I get the error message `Cannot convert type Android.Support.Design.Widget.FloatingActionButton to Android.Support.V7.Widget.AppCompatButton'`, in Xamarin do I have to do something else? – Uriel Arvizu May 26 '17 at 20:34

0 Answers0