0
点赞
收藏
分享

微信扫一扫

Android(十二):自定义控件


展示

Android(十二):自定义控件_自定义控件

自定义控件

<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);
}
}
}


举报

相关推荐

0 条评论