【问题标题】:How to set a background image to an entry cell in xamarin.forms如何将背景图像设置为 xamarin.forms 中的条目单元格
【发布时间】:2016-08-18 14:29:55
【问题描述】:
我已使用自定义渲染以 xamarin 形式显示 IOS 和 android 的条目单元格。我可以更改单元格的背景颜色,但有没有办法将任何背景图像设置为条目单元格。还有如何隐藏默认的android入口单元格中的下栏线。
我在 PCl 中的自定义输入单元格:
<local:MyEntry Placeholder="Placeholder" PlaceholderColor="Grey" TextColor="Black"/>
【问题讨论】:
标签:
xamarin
xamarin.forms
custom-renderer
【解决方案1】:
是的,您可以将任何背景图像设置为条目单元格。
对于IOS,您需要这样做:
Control.BorderStyle = UITextBorderStyle.None;
UIImage img = UIImage.FromFile("ImageName.png");
Control.Background = img;
对于android:
Control.Background = ContextCompat.GetDrawable(Context, Resource.Drawable.ImageName);
要隐藏android 中的下划线,请使用:
Control.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
完成此操作后,您可以从xaml 调整入口单元格背景图像的高度宽度,如下所示:
<local:MyEntry Placeholder="placeholder" PlaceholderColor="Grey" TextColor="Black" WidthRequest="200" HeightRequest="50"/>