我在Xamarin.Forms应用程序中创建了一个自定义的选择器呈现器,在IOS上它工作得很好,但当我运行Android时它崩溃了。
我已经更新了Visual Studio2017,并且正在运行Xamarin.Forms 2.3.4.247。
目标Android版本设置为7.1(6.0上出现相同错误)最小Android版本设置为4.3
using System; using Xamarin.Forms; namespace Attest.Combustivel.Infra.Application.Controls { public class CustomPicker : Picker { public static readonly BindableProperty FontSizeProperty = BindableProperty.Create(p => p.FontSize, 22); public Double FontSize { get { return (double)GetValue(FontSizeProperty); } set { if (this.FontSize != value) { SetValue(FontSizeProperty, value); } } } } }
using Xamarin.Forms; using Xamarin.Forms.Platform.Android; [assembly: ExportRenderer(typeof(Attest.Combustivel.Infra.Application.Controls.CustomPicker), typeof(Attest.Combustivel.Target.Droid.Renderers.DroidCustomPickerRenderer))] namespace Attest.Combustivel.Target.Droid.Renderers { public class DroidCustomPickerRenderer : PickerRenderer { protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); //if (Control == null) //{ // return; //} //var customPicker = e.NewElement as CustomPicker; //if (customPicker != null) //{ // Control.TextSize = Convert.ToSingle(customPicker.FontSize); //} } } }
using Attest.Combustivel.Infra.Application.Controls; using CoreGraphics; using System; using UIKit; using Xamarin.Forms; using Xamarin.Forms.Platform.iOS; [assembly: ExportRenderer(typeof(Attest.Combustivel.Infra.Application.Controls.CustomPicker), typeof(Attest.Combustivel.Target.Droid.Renderers.IOSCustomPickerRenderer))] namespace Attest.Combustivel.Target.Droid.Renderers { public class IOSCustomPickerRenderer : PickerRenderer { protected override void OnElementChanged(ElementChangedEventArgs e) { base.OnElementChanged(e); if (Control == null) { return; } var customPicker = e.NewElement as CustomPicker; // FontSize if (customPicker?.FontSize != null) { Control.Font = UIFont.FromName(".SF UI Text", Convert.ToSingle(customPicker.FontSize)); } } } }
06-20 16:15:02.261 W/art ( 7541): JNI RegisterNativeMethods: attempt to register 0 native methods for md5b60ffeb829f638581ab2bb9b1a7f4f3f.TableViewRenderer
06-20 16:15:02.261 W/art ( 7541): JNI RegisterNativeMethods: attempt to register 0 native methods for md5718175f0eae2ce5b6bb8ba01f33420ae.DroidCustomTableViewRenderer
06-20 16:15:04.911 D/Mono ( 7541): DllImport attempting to load: '/system/lib/liblog.so'.
06-20 16:15:04.911 D/Mono ( 7541): DllImport loaded library '/system/lib/liblog.so'.
06-20 16:15:04.911 D/Mono ( 7541): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
06-20 16:15:04.911 D/Mono ( 7541): Searching for '__android_log_print'.
06-20 16:15:04.911 D/Mono ( 7541): Probing '__android_log_print'.
06-20 16:15:04.911 D/Mono ( 7541): Found as '__android_log_print'.
06-20 16:15:04.921 I/MonoDroid( 7541): UNHANDLED EXCEPTION:
06-20 16:15:04.981 I/MonoDroid( 7541): System.ArgumentException: element is not of type Xamarin.Forms.TableView
06-20 16:15:04.981 I/MonoDroid( 7541): Parameter name: element
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00008] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:135
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Platform.cs:289
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x00023] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:84
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00104] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:217
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:68
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:335
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00111] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:199
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:137
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Platform.cs:289
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x00023] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:84
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00104] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:217
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:68
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:335
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00111] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:199
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:137
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x0001f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Platform.cs:289
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x00023] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:84
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x00104] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:217
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementPackager.cs:68
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:335
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00111] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:199
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\VisualElementRenderer.cs:137
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Support.V4.App.FragmentManager fragmentManager) [0x00031] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\Platform.cs:325
06-20 16:15:04.981 I/MonoDroid( 7541): at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x00008] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:67
06-20 16:15:04.981 I/MonoDroid( 7541): at Android.Support.V4.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00022] in <27c17fe440cf491ba8255bcefade6e02>:0
06-20 16:15:04.981 I/MonoDroid( 7541): at (wrapper dynamic-method) System.Object:63a8a4b1-f4fe-4a75-89d0-ed93d90f2880 (intptr,intptr,intptr,intptr,intptr)
我们从异常中发现,同一类型有更多的呈现器。
我已经声明了一个用于iOS的自定义渲染器(和Android-工作正常)。 自定义呈现器主要设置背景色和文本颜色。 设置文本颜色对启用和禁用状态都很好,但我在不同状态下设置按钮的背景颜色时遇到了麻烦。 我无法找到任何关于Xamarin自定义呈现器的文档,而且Xamarin的一个已知错误是,我无法在Visual Studio中获得任何适用于iOS类的智能感知,到目前为止,我已经使用了我能找到的关于该主
本文向大家介绍Android自定义View实现角度选择器,包括了Android自定义View实现角度选择器的使用技巧和注意事项,需要的朋友参考一下 首先来看一下Google Photos的效果 实现最终的效果: 实现思路 仔细观察这个效果,先分析构成结构,我把它分成三部分: 1、表示刻度的点 2、相应点上方的数字 3、控件中央的当前刻度与三角 可以看出,构成元素十分简单,不
本文向大家介绍iOS自定义日期选择器,包括了iOS自定义日期选择器的使用技巧和注意事项,需要的朋友参考一下 前言 封装了一个日期选择器,解决两个问题: 1、点击textField,键盘弹出和日期选择器弹出的逻辑处理; 2、同一个界面需要多次用到日期选择器时,判断点击的textField; 一、封装日期选择器类YCDatePickerView 1、新建一个类,基于UIView,取名YCDatePic
本文向大家介绍iOS实现自定义日期选择器示例,包括了iOS实现自定义日期选择器示例的使用技巧和注意事项,需要的朋友参考一下 iOS自定义日期选择器,下面只是说明一下怎么用,具体实现请在最后下载代码看看; 效果如下: .h文件解析 选择日期选择器样式 DateStyleShowYearMonthDayHourMinute :显示年月日时分 DateStyleShowMonthDayHourMinut
我想要一个日期选择器只显示月份和年份。我已经定制了日期选择器来这样做,即,从选择器中移除“Day”字段,但在Android中,Lollipop得到的选择器有Day、Month和year。下面是我的一段代码。请帮我弄清楚问题所在。提前道谢。
PHP 7.0.33和yii2.0.16在这里。 我需要定制一个yii2日期时间选择器,我在某个时候卡住了。我看了几个扩展,我最终使用了下面的一个,因为它让我最接近我想要实现的目标: https://github.com/kartik-v/yii2-date-range 所以,我的代码是: 结果是: 几乎不错,但是有几件事我不知道我是否可以定制: > 当我开始选择日期、时间、分钟时,目标表单元素的