OGeek|极客世界-中国程序员成长平台

标题: android - Xamarin 表单 : Is it possible to add disclosure indicator in Android? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-9 06:00
标题: android - Xamarin 表单 : Is it possible to add disclosure indicator in Android?

enter image description here

我有一个 TextCell,它在我的 Xamarin Forms 应用程序的 iOS 端添加了一个披露指示器:

<TextCell Text="Japanese" StyleId="disclosure"/>

我也想为 android 端做同样的事情,但我似乎找不到任何自定义渲染器来做这样的事情。

有人能做到吗?如果有人能指出我的方向,我将不胜感激。



Best Answer-推荐答案


根据design guidelines ,建议不要在 Android 中的订单项上使用右指向插入符(披露指示符)。

Don't use right-pointing carets on line items

A common pattern on other platforms is the display of right-pointing carets on line items that allow the user to drill deeper into additional content.

Android does not use such indicators on drill-down line items. Avoid them to stay consistent with the platform and in order to not have the user guess as to what the meaning of those carets may be.

enter image description here

编辑 1:

但如果您仍想添加指标,您可以使用图像。

Download the icon并将作为可绘制添加到android项目。并将渲染器注册如下:

[assembly: ExportRenderer(typeof(TextCell), typeof(StandardTextCellRenderer))]
namespace AppNamespace.Droid
{
    public class StandardTextCellRenderer : TextCellRenderer
    {

        protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context)
        {
            var cell = base.GetCellCore(item, convertView, parent, context);

            switch (item.StyleId)
            {
                case "disclosure":
                    var bmp = BitmapFactory.DecodeResource(cell.Resources, Resource.Drawable.ic_chevron_right);
                    var bitmapDrawable = new BitmapDrawable(cell.Resources, Bitmap.CreateScaledBitmap(bmp, 50, 50, true));
                    bitmapDrawable.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
                    cell.SetBackground(bitmapDrawable);
                    break;
            }
            return cell;
        }
    }
}

关于android - Xamarin 表单 : Is it possible to add disclosure indicator in Android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46989358/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://www.ogeek.cn/) Powered by Discuz! X3.4