【发布时间】:2019-08-22 02:07:36
【问题描述】:
我想用右侧的图标进入。
我使用 Xamarin 表单 + PCL
我已经在IOS和Android中实现了主要部分。
我在条目中添加了图标,这看起来很棒............
但是! 当用户单击此图标时,我需要捕捉。
在 Ios 中我做的很简单....但是 Android .. 我做不到(((
Xamarin.Droid CUSTOM RENDER 进入
FormsEditText editText = Control;
if(!string.IsNullOrEmpty(element.Image))
{
Drawable d = GetDrawable(element.Image);
switch(element.ImageAlignment)
{
case ImageAlignment.Left:
editText.SetCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
break;
case ImageAlignment.Right:
editText.SetCompoundDrawablesWithIntrinsicBounds(null, null, d, null);
break;
}
}
private BitmapDrawable GetDrawable(string imageEntryImage)
{
int resID = Resources.GetIdentifier(imageEntryImage, "drawable", Context.PackageName);
Android.Graphics.Drawables.Drawable drawable = ContextCompat.GetDrawable(Context, resID);
Bitmap bitmap = ((BitmapDrawable)drawable).Bitmap;
var im = new BitmapDrawable(Resources, Bitmap.CreateScaledBitmap(bitmap, element.ImageWidth * 4, element.ImageHeight * 4, true));
return im;
}
所以我需要在这个图标上捕捉点击/触摸事件。
谢谢。
【问题讨论】:
-
如果以下解决方案不起作用,请告诉我,以便我添加答案!