【发布时间】:2017-08-12 10:56:26
【问题描述】:
我正在尝试通过 ButtonRender 实现 android 按钮的功能。当我尝试加入“.LongClick”和“.touch”时出现问题,因为它不会启动长点击事件。
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
this.SetBackgroundResource(Resource.Drawable.button);
base.OnElementChanged(e);
Android.Widget.Button thisButton = Control as Android.Widget.Button;
thisButton.LongClickable = true;
thisButton.LongClick += delegate
{
string s = "";
};
thisButton.Touch += (object sender, Android.Views.View.TouchEventArgs e2) =>
{
if (e2.Event.Action == MotionEventActions.Down)
{
.
.
.
}
else if (e2.Event.Action == MotionEventActions.Up)
{
.
.
.
}
else if (e2.Event.Action == MotionEventActions.HoverExit || e2.Event.Action == MotionEventActions.Cancel)
{
.
.
.
}
else if (e2.Event.Action == MotionEventActions.Move)
{
.
.
.
}
};
}
【问题讨论】:
-
您确定要按钮的
Touch事件吗?Click活动不适合您吗? -
你检查我的答案了吗?有什么问题吗?
-
我正在尝试实现它,但我没有多少时间。今晚我看完了,我告诉你一些事情。感谢您的关注!
标签: xamarin xamarin.android xamarin.forms