展示
自定义控件
<android_by_csharp.Scripts.ShowToast
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#5daf34"
android:textColor="#ffffff"
android:text="按钮(自定义控件)" />
// 目录: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);
}
}
}