展示
自定义控件
// 目录:scripts/ShowToast.cs
using System;
using Android.App;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Content;
namespace android_by_csharp.scripts
{
public class ShowToast : Button
{
public ShowToast(Context context, IAttributeSet attrs) : base(context, attrs)
{
}
public override bool OnTouchEvent(MotionEvent e)
{
switch (e.Action)
{
case MotionEventActions.Down:
Toast.MakeText(Application.Context, "自定义控件", ToastLength.Long)?.Show();
break;
case MotionEventActions.Up:
case MotionEventActions.Cancel:
break;
}
return base.OnTouchEvent(e);
}
}
}