为什么我不能在Xamarin.Android中更改Floating Action Button的BackgroundTintColor?

时间:2017-05-26 17:47:15

标签: android xamarin xamarin.android floating-action-button

我正在使用Xamarin Studio 6.1.3并尝试最新的Xamarin Android支持设计库25.3.1,我的目标设置为API 24,最小版本为19。

我在我的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" />

我希望以编程方式更改背景色调颜色,我尝试使用以下代码:

fab.BackgroundTintList = GetInProgressColor();

GetInProgressColor方法是:

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

但是当我的代码在运行时调用BackgroundTintList属性时,我得到错误:

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)

为什么会抛出此错误?我应该可以修改背景色调颜色,因为我正在使用设计支持库,我能够显示浮动操作按钮,所以我应该可以修改它的属性,或者有不同的方法来操纵它的属性在运行

0 个答案:

没有答案